Ulysses

General => Developers Corner => Topic started by: Chironex on February 29, 2008, 05:05:47 PM

Title: Just a small coding tip you may ignore (no offense)
Post by: Chironex on February 29, 2008, 05:05:47 PM
It's something that i learned from my favorite language, Pawn, and hopefully it works in Lua too.

This can be very useful for making a nice presentation in the console, i think about the command 'ulx help'.

You all know about %s, in a string format ?, Well, you can use for example %20s, which will insert empty spaces at the begining of the string. Like
Code: [Select]
local str = string.format("%20s\t%s", k, v)
Msg( str )
Supposing this is in a for loop, and k and v are strings, will output things like

Code: [Select]
               hello    blabla
      anothercommand    etc

I haven't tested for numbers but it should work too, aligned to the right i guess (in Pawn, strings are aligned to the left, numbers and floats to the right)

I think this can improve 'readability' (sorry don't know the english word) of the long help list.


PS: For floats, %4.1f should output something like that:
Code: [Select]
  20.5
 -12.8
   2.4
 100.7

It's something that i would like Garry to implement in the function util.TableToKeyValue, and others things like that, instead of tabs.
Title: Re: Just a small coding tip you may ignore (no offense)
Post by: Megiddo on February 29, 2008, 05:09:52 PM
We use format (which is a direct port from sprintf (http://cplusplus.com/reference/clibrary/cstdio/sprintf.html)) all over our code. It is not possible to use it in help as we have it though, due to the limiting nature of the number of characters we can fit on a line.
Title: Re: Just a small coding tip you may ignore (no offense)
Post by: Chironex on February 29, 2008, 05:28:58 PM
:(

Shouldn't it be possible to wrap to next line after a certain character count? to create like:
Code: [Select]
¤     command  -  blablablablablabalbalbalbalab lbalablabla ablaba laba lab lab alab alb
                  blablabalbal lbalab albalba alba laba lba a.
¤  anotherone  -  blablablablablabalbalbalbalab lbalablabla ablaba laba lab lab alab alb
                  blablabalbal lbalab albalba alba laba lba a.

Sorry for blablating :)
Title: Re: Just a small coding tip you may ignore (no offense)
Post by: Megiddo on February 29, 2008, 11:51:37 PM
Do you really want the output to be even longer than it already is? ;)