Client Management Suite

 View Only

Hacked and Statically Compiled Whiptail for Linux Dialog Boxes  

Sep 07, 2011 03:32 PM

This download is a rather esoteric one.

I recently found myself struggling a bit with the whiptail dialog. The problem I faced was that the menu facility in whiptail requires data in tag-text pairs. This allows you to for example create a file menu which looks like,

1  Load File
2  Save File
3  Exit

Where the tag here is the number field, and the text is, well, the text. The way whiptail works is that when you select the entry you want, it throws the tag field from the selected item to standard error. This is generally exactly what you want, but my case usage which came up required that the tag field not be presented on the screen.

The scenario I came across was selecting from a menu a job from the Altiris eXpress database. In this case I wanted the jobID to be the tag, and the text field to be the job name. I wanted the user to select the job (from the human readable name) and for the menu to dump the JobID to standard error.

For example, my tag-text pairs would have been something like,

1001590 'Deploy Staff XP Computer'
1001633 'Deploy Staff Win7 Computer'
1001460 'Deliver Vanilla XP x86 Scripted Install'

But in my menu I wanted displayed just the following,

 'Deploy Staff XP Computer'
 'Deploy Staff Win7 Computer'
 'Deliver Vanilla XP x86 Scripted Install'

This was just not possible with whiptail. There is no option to hide the tag, which meant that the JobID would always have to be made visible if I wanted it selectable as output. Very messy. 

To workaround this, I decided to hack whiptail. Although initially daunting the the process turned out to be fairly straight forward,

  1. Download the newt-0.52.10 rpm source
     
  2. Find where the menu box code was and hack it
    This turned out to be in dialogboxes.c -and all I did was locate section in the code which presented the List box to the screen, and stop the tag from being printed. Put a comment in with 'ILA' so I could later find the changes quickly.
     
  3. Compile
    First a quick edit of config.h to update the version number to '0.52.10-ILA01' to reflect my horrible hack. Then I did a 'make whiptail' to ensure all the object files were generated. After that it was static compile with 'gcc --static -g -o whiptail whiptail.o dialogboxes.o -L . -lnewt -lslang -lpopt' and then a 'strip whiptail' to make it a bit lighter by removing symbols.

 

If I had more time, I'd probably spend a bit more time and add the tag hide as an option, rather than make it always hidden. But.. time is short...

Attached is the code....

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Related Entries and Links

No Related Resource entered.