Author Topic: Just a small coding tip you may ignore (no offense)  (Read 3154 times)

0 Members and 1 Guest are viewing this topic.

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Just a small coding tip you may ignore (no offense)
« 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.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: Just a small coding tip you may ignore (no offense)
« Reply #1 on: February 29, 2008, 05:09:52 PM »
We use format (which is a direct port from sprintf) 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.
Experiencing God's grace one day at a time.

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Just a small coding tip you may ignore (no offense)
« Reply #2 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 :)
« Last Edit: February 29, 2008, 05:39:14 PM by Kyzer »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: Just a small coding tip you may ignore (no offense)
« Reply #3 on: February 29, 2008, 11:51:37 PM »
Do you really want the output to be even longer than it already is? ;)
Experiencing God's grace one day at a time.