Changeset a35b458 in mainline for tools/xtui.py


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/xtui.py

    r3061bc1 ra35b458  
    3535def call_dlg(dlgcmd, *args, **kw):
    3636        "Wrapper for calling 'dialog' program"
    37        
     37
    3838        indesc, outdesc = os.pipe()
    3939        pid = os.fork()
     
    4141                os.dup2(outdesc, 2)
    4242                os.close(indesc)
    43                
     43
    4444                dlgargs = [dlgcmd]
    4545                for key, val in kw.items():
    4646                        dlgargs.append('--' + key)
    4747                        dlgargs.append(val)
    48                
     48
    4949                dlgargs += args
    5050                os.execlp(dlgcmd, *dlgargs)
    51        
     51
    5252        os.close(outdesc)
    53        
     53
    5454        try:
    5555                errout = os.fdopen(indesc, 'r')
     
    6161                os.system('reset')
    6262                raise
    63        
     63
    6464        if (not os.WIFEXITED(status)):
    6565                # Reset terminal
    6666                os.system('reset')
    6767                raise EOFError
    68        
     68
    6969        status = os.WEXITSTATUS(status)
    7070        if (status == 255):
    7171                raise EOFError
    72        
     72
    7373        return (status, data)
    7474
     
    7979except ImportError:
    8080        newt = False
    81        
     81
    8282        dlgcmd = os.environ.get('DIALOG', 'dialog')
    8383        if (call_dlg(dlgcmd, '--print-maxsize')[0] != 0):
     
    9191def width_fix(screen, width):
    9292        "Correct width to screen size"
    93        
     93
    9494        if (width + width_extra > screen.width):
    9595                width = screen.width - width_extra
    96        
     96
    9797        if (width <= 0):
    9898                width = screen.width
    99        
     99
    100100        return width
    101101
    102102def height_fix(screen, height):
    103103        "Correct height to screen size"
    104        
     104
    105105        if (height + height_extra > screen.height):
    106106                height = screen.height - height_extra
    107        
     107
    108108        if (height <= 0):
    109109                height = screen.height
    110        
     110
    111111        return height
    112112
    113113def screen_init():
    114114        "Initialize the screen"
    115        
     115
    116116        if (newt):
    117117                return snack.SnackScreen()
    118        
     118
    119119        return None
    120120
    121121def screen_done(screen):
    122122        "Cleanup the screen"
    123        
     123
    124124        if (newt):
    125125                screen.finish()
     
    127127def choice_window(screen, title, text, options, position):
    128128        "Create options menu"
    129        
     129
    130130        maxopt = 0
    131131        for option in options:
     
    133133                if (length > maxopt):
    134134                        maxopt = length
    135        
     135
    136136        width = maxopt
    137137        height = len(options)
    138        
     138
    139139        if (newt):
    140140                width = width_fix(screen, width + width_extra)
    141141                height = height_fix(screen, height)
    142                
     142
    143143                if (height > 3):
    144144                        large = True
    145145                else:
    146146                        large = False
    147                
     147
    148148                buttonbar = snack.ButtonBar(screen, ('Done', 'Cancel'))
    149149                textbox = snack.TextboxReflowed(width, text)
    150150                listbox = snack.Listbox(height, scroll = large, returnExit = 1)
    151                
     151
    152152                cnt = 0
    153153                for option in options:
    154154                        listbox.append(option, cnt)
    155155                        cnt += 1
    156                
     156
    157157                if (position != None):
    158158                        listbox.setCurrent(position)
    159                
     159
    160160                grid = snack.GridForm(screen, title, 1, 3)
    161161                grid.add(textbox, 0, 0)
    162162                grid.add(listbox, 0, 1, padding = (0, 1, 0, 1))
    163163                grid.add(buttonbar, 0, 2, growx = 1)
    164                
     164
    165165                retval = grid.runOnce()
    166                
     166
    167167                return (buttonbar.buttonPressed(retval), listbox.current())
    168168        elif (dialog):
    169169                if (width < 35):
    170170                        width = 35
    171                
     171
    172172                args = []
    173173                cnt = 0
     
    175175                        args.append(str(cnt + 1))
    176176                        args.append(option)
    177                        
     177
    178178                        cnt += 1
    179                
     179
    180180                kw = {}
    181181                if (position != None):
    182182                        kw['default-item'] = str(position + 1)
    183                
     183
    184184                status, data = call_dlg(dlgcmd, '--title', title, '--extra-button', '--extra-label', 'Done', '--menu', text, str(height + height_extra), str(width + width_extra), str(cnt), *args, **kw)
    185                
     185
    186186                if (status == 1):
    187187                        return ('cancel', None)
    188                
     188
    189189                try:
    190190                        choice = int(data) - 1
    191191                except ValueError:
    192192                        return ('cancel', None)
    193                
     193
    194194                if (status == 0):
    195195                        return (None, choice)
    196                
     196
    197197                return ('done', choice)
    198        
     198
    199199        sys.stdout.write("\n *** %s *** \n%s\n\n" % (title, text))
    200        
     200
    201201        maxcnt = len(str(len(options)))
    202202        cnt = 0
     
    204204                sys.stdout.write("%*s. %s\n" % (maxcnt, cnt + 1, option))
    205205                cnt += 1
    206        
     206
    207207        sys.stdout.write("\n%*s. Done\n" % (maxcnt, '0'))
    208208        sys.stdout.write("%*s. Quit\n\n" % (maxcnt, 'q'))
    209        
     209
    210210        while True:
    211211                if (position != None):
     
    217217                                sys.stdout.write("Selection[0]: ")
    218218                inp = sys.stdin.readline()
    219                
     219
    220220                if (not inp):
    221221                        raise EOFError
    222                
     222
    223223                if (not inp.strip()):
    224224                        if (position != None):
     
    229229                                else:
    230230                                        inp = '0'
    231                
     231
    232232                if (inp.strip() == 'q'):
    233233                        return ('cancel', None)
    234                
     234
    235235                try:
    236236                        choice = int(inp.strip())
    237237                except ValueError:
    238238                        continue
    239                
     239
    240240                if (choice == 0):
    241241                        return ('done', 0)
    242                
     242
    243243                if (choice < 1) or (choice > len(options)):
    244244                        continue
    245                
     245
    246246                return (None, choice - 1)
    247247
    248248def error_dialog(screen, title, msg):
    249249        "Print error dialog"
    250        
     250
    251251        width = len(msg)
    252        
     252
    253253        if (newt):
    254254                width = width_fix(screen, width)
    255                
     255
    256256                buttonbar = snack.ButtonBar(screen, ['Ok'])
    257257                textbox = snack.TextboxReflowed(width, msg)
    258                
     258
    259259                grid = snack.GridForm(screen, title, 1, 2)
    260260                grid.add(textbox, 0, 0, padding = (0, 0, 0, 1))
Note: See TracChangeset for help on using the changeset viewer.