Author: Tobias Schlitt
Date: 2006-01-19 10:44:59 +0100 (Thu, 19 Jan 2006)
New Revision: 1972

Log:
- Intermediate commit for DR.

Added:
   packages/ConsoleTools/trunk/docs/img/tutorial_example_08.png
   packages/ConsoleTools/trunk/docs/img/tutorial_example_09.png
   packages/ConsoleTools/trunk/docs/tutorial_example_09.php
Modified:
   packages/ConsoleTools/trunk/docs/tutorial.txt
   packages/ConsoleTools/trunk/docs/tutorial_example_08.php

Added: packages/ConsoleTools/trunk/docs/img/tutorial_example_08.png
===================================================================
(Binary files differ)


Property changes on: 
packages/ConsoleTools/trunk/docs/img/tutorial_example_08.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: packages/ConsoleTools/trunk/docs/img/tutorial_example_09.png
===================================================================
(Binary files differ)


Property changes on: 
packages/ConsoleTools/trunk/docs/img/tutorial_example_09.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: packages/ConsoleTools/trunk/docs/tutorial.txt
===================================================================
--- packages/ConsoleTools/trunk/docs/tutorial.txt       2006-01-19 09:07:28 UTC 
(rev 1971)
+++ packages/ConsoleTools/trunk/docs/tutorial.txt       2006-01-19 09:44:59 UTC 
(rev 1972)
@@ -289,10 +289,13 @@
 progressbar. The second parameter provided is the number to which the
 progressbar shall count to. This meanst, that we have to call 15 times the
 ezcConsoleProgressbar::advance() (line 11) method until the progressbar 
reaches 
-the 100% value. That is basically all you have to do, to create a basic 
-progressbar, which will look like this after we called advance() for the first 
-time:
+the 100% value. Note, that we are emulating some action here, by making the
+program sleep for a random time. In the real world you would have some time
+consuming action here.
 
+This is basically all you have to do, to create a basic progressbar, which 
will 
+look like this after we called advance() for the a couple of times:
+
 .. image:: img/tutorial_example_06.png
 
 The bar will then constantly move forward, everytime you call advance() and
@@ -351,8 +354,50 @@
 So, let's take a look at the little brother of ezcConsoleProgressbar, the
 ezcConsoleStatusbar:
 
+.. include:: tutorial_example_08.php
+   :literal:
 
+As usual, we define some output format, this time one called "success" and the
+other one called "failure". These formats are directly used in the $options
+array we define for our ezcConsoleStatusbar. This simple class takes only 2
+possible options: "successChar" will be used to indicate a successful action
+and "failureChar" will be used to indicate a failed action.
 
+Then we instanciate the statusbar object (line 15) using this options and our
+ezcConsoleOutput object and the options. Again we emulate some action by using
+a for-loop and some random sleeping (line 21) time and this time we also 
emulate 
+random success and failure values (line 19). Adding success and failure values 
to 
+the statusbar is easy: We just call the ezcConsoleStatusbar::add() method and
+submit either true (indicating success) or false to it.
+
+Finally we get the number of successes and failures from the statusbar by
+calling ezcConsoleStatusbar::getSuccessCount() and
+ezcConsoleStatusbar::getFailureCount() to display them to the user. Take a
+look at the result here:
+
+.. image:: img/tutorial_example_08.png
+
+If you want to know more about indicating progress to the user from your shell
+application, take a look at the API documentation of ezcConsoleProgressbar_ and
+ezcConsoleStatusbar_.
+
+.. _ezcConsoleProgressbar: 
http://ez.no/doc/components/view/(file)/1.0rc1/ConsoleTools/ezcConsoleProgressbar.html
+.. _ezcConsoleStatusbar: 
http://ez.no/doc/components/view/(file)/1.0rc1/ConsoleTools/ezcConsoleStatusbar.html
+
+Large data served on a table
+----------------------------
+
+Actually it should have been "in a table", but this way it sounded funnier. ;)
+Anyway: Whenever you want to display a large amount of structured data, a
+table layout is what you need. While this can easily be achieved in HTML, it's
+pretty hard to create a table on the console. Therefore, the ConsoleTools
+package also has a class to generate tables: ezcConsoleTable. Before we look
+at some example code, let me first show you, how the table will look like,
+that we want to create:
+
+
+
+
 
 ..
    Local Variables:

Modified: packages/ConsoleTools/trunk/docs/tutorial_example_08.php
===================================================================
--- packages/ConsoleTools/trunk/docs/tutorial_example_08.php    2006-01-19 
09:07:28 UTC (rev 1971)
+++ packages/ConsoleTools/trunk/docs/tutorial_example_08.php    2006-01-19 
09:44:59 UTC (rev 1972)
@@ -5,24 +5,23 @@
 $output = new ezcConsoleOutput();
 
 $output->formats->success->color = 'green';
-$output->formats->success->style = array( 'bold' );
-
 $output->formats->failure->color = 'red';
-$output->formats->failure->style = array( 'bold' );
 
-$bar = new ezcConsoleStatusbar( $output );
+$options = array( 
+    'successChar' => $output->formatText( '+', 'success' ),
+    'failureChar' => $output->formatText( '-', 'failure' ),
+);
 
-$bar->options->successChar = $output->formatText( '+', 'success' );
-$bar->options->failureChar = $output->formatText( '-', 'failure' );
+$status = new ezcConsoleStatusbar( $output, $options );
 
-for ( $i = 0; $i < 1024; $i++ )
+for ( $i = 0; $i < 120; $i++ )
 {
-    $bar->advance();
+    $nextStatus = ( bool )mt_rand( 0,1 );
+    $status->add( $nextStatus );
     usleep(  mt_rand( 200, 2000 ) );
 }
 
-$bar->finish();
-
 $output->outputLine();
+$output->outputLine( 'Successes: ' . $status->getSuccessCount() . ', Failures: 
' . $status->getFailureCount() );
 
 ?>

Added: packages/ConsoleTools/trunk/docs/tutorial_example_09.php
===================================================================
--- packages/ConsoleTools/trunk/docs/tutorial_example_09.php    2006-01-19 
09:07:28 UTC (rev 1971)
+++ packages/ConsoleTools/trunk/docs/tutorial_example_09.php    2006-01-19 
09:44:59 UTC (rev 1972)
@@ -0,0 +1,42 @@
+<?php
+
+require_once 'tutorial_autoload.php';
+
+$output = new ezcConsoleOutput();
+
+$output->formats->headBorder->color = 'blue';
+$output->formats->normalBorder->color = 'gray';
+
+$output->formats->headContent->color = 'blue';
+$output->formats->headContent->style = array( 'bold' );
+
+$data = array( 
+    array( 'Name', 'Nationality', 'Birthday' ),
+    array( 'Derick Rethans', 'Dutch', '1978-12-22' ),
+    array( 'Frederik Holljen', 'Canadian / Norwegian', '1978-11-15' ),
+    array( 'Jan Borsodi', 'Norwegian', '1977-10-13' ),
+    array( 'Raymond Bosman', 'Dutch', '1979-07-24' ),
+    array( 'Tobias Schlitt', 'German', '1980-05-19' ),
+);
+
+$table = new ezcConsoleTable( $output, 78 );
+
+$table->options->defaultBorderFormat = 'normalBorder';
+
+$table[0]->borderFormat = 'headBorder';
+$table[0]->format = 'headContent';
+
+foreach ( $data as $row => $cells )
+{
+    foreach ( $cells as $cell )
+    {
+        $table[$row][]->content = $cell;
+    }
+}
+
+$output->outputLine( 'eZ components team:' );
+$table->outputTable();
+$output->outputLine();
+
+
+?>


Property changes on: packages/ConsoleTools/trunk/docs/tutorial_example_09.php
___________________________________________________________________
Name: svn:eol-style
   + native

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to