Working on a top status bar for Tinyfugue

by David Sexton Aug 1 2010 01:45 PM PST

 

I'm currently working on a top status bar for Tinyfugue.  This is mostly done inside of file output.c.  So far the hardest part has been deciding on how to integrate the top status bar without breaking any currently working scripts.  Adding macros such as /status_add_top and /status_rm_top is too cumbersome.  Using the -r row option of all current /status_* macros with negative numbers would allow current scripts to remain unchanged, and require only the row specifier be changed in order to move items currently on the bottom status bar to the top status bar.

 

Tinyfugue already has the -r option to the /status* macros.  This option specifies the row on which to place the status field, and is 0 based.  When using the -r option, -r0 would put the field on the first status line and -r2 would put the field on line 3.

 

It is possible to extend the use of the -r option to provide a top status bar by allowing the -r option to take negative numbers.  Currently this is prevented in the source code by making all row values less than 0 equal to 0.  After removing this check, it is possible to use negative numbers to designate rows in the top status bar.  The main issue with using those negative numbers is that now the way in which top and bottom status rows are accessed is different.  -r0 is the first row of the bottom status bar, but -r-1 is the first row of top status bar.  This breaks the symmetry of 1 and -1 since 1 would be bottom row 2 and -1 would be top row 1.

 

One method to achieve this dual use of the -r option is to mirror the current bottom status bar system.  Right now the bottom status area consists of a group of arrays where the row number from the -r option is used as the array index.  The top status bar could have its own set of arrays that are created and initialized in the same manner as the bottom status arrays.  Then in the code, a check could be made for a negative number and a conversion be done on that number to get the current array index into the top status arrays.  If the row was negative, the index would be set to (-row - 1).  This negates the row number and then subtracts 1.  Using this logic, -1 turns in to 0 (-1 to 1 then subtract 1 to get 0), -2 turns in to 1, etc.  Using this method, most of the current code can be left unmodified.  The main work is switching which set of arrays the code is working on from the bottom status arrays to the top status arrays.  The main drawbacks to the mirrored set of arrays is the continual conversion of the row in to an index for the top status arrays and the increased complexity of having 2 sets of arrays and correctly switching between the two.

 

An alternate method would be to use the negative row number from the -r option as the actual index into the current arrays.  Normally this would not work since a negative index in to an array is generally out of bounds.  However, if an array had a size equal to the combined size of the top and bottom status arrays, then a fake index could be used to represent 0.

 

For an array with 10 total status lines (5 for the top status bar and 5 for the bottom status bar), a fake index could be created at 5 and defined as the 0 for the array.  Then the row number from the -r option would be added to the fake index in order to get the real index in to the array.  To find the real index, add the fake index and row number together.  In other words, "real index = (fake index + row number)". There is a example below that demonstrates how this works.  This method also benefits from being able to use most of the current code without modification.  The main drawbacks to this method are keeping the top and bottom indexes in sync, ensuring that all array lookups are done from the fake index instead of 0, and that iterations over the whole array cover all items.

 

Example:


[0] - [1] - [2] - [3] - [4] - [5] - [6] - [7] - [8] - [9]
 ^         Top           ^     ^        Bottom         ^
 `-----------------------'     +-----------------------'
                               ^
Fake index at 5 ---------------'


If using -r2 then row = 2 and the real index is (5 + 2) = 7

If using -r-2 then row = -2 and the real index is (5 + -2) = 3

Tags:

Tinyfugue

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

Name: David Sexton

Currenty City: Portland, OR

I'm a full time programmer (mainly Microsoft stack), just looking for a spot to put stuff that I can't find a better place for.

Month List