diff options
author | Helmut Grohne <helmut@subdivi.de> | 2013-06-02 14:03:09 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2013-06-02 14:03:09 +0200 |
commit | ccf38158e6e7fefd2b7bdbde243da98ffff79270 (patch) | |
tree | 2612ed2e5c8c9522a768d655ce6bd8e5c819bc0b | |
parent | 08db538d4de4fc4dcd99bbb23db9017f1a56b4b3 (diff) | |
download | tcvt-ccf38158e6e7fefd2b7bdbde243da98ffff79270.tar.gz |
allow specifying the number of columns
-rwxr-xr-x | optcvt.sh | 2 | ||||
-rw-r--r-- | tcvt.1 | 22 | ||||
-rwxr-xr-x | tcvt.py | 19 |
3 files changed, 33 insertions, 10 deletions
@@ -8,6 +8,8 @@ COLUMNS="${SIZE#* }" if test "$COLUMNS" -ge $((2*$MINWIDTH+1)); then exec $TCVT "$@" +elif test -z "$@"; then + exec "$SHELL" else exec "$@" fi @@ -4,7 +4,7 @@ tcvt - two column virtual terminal .Sh SYNOPSIS .nf -\fBtcvt\fP \fIprogram options\fP +\fBtcvt\fP \fItcvt options\fP \fIprogram options\fP .PP \fBoptcvt\fP \fIprogram options\fP .fi @@ -13,11 +13,25 @@ The two column virtual terminal emulates a virtual terminal inside another virtu The emulated virtual terminal is twice as tall and half as wide as the original terminal. The upper half of the virtual terminal goes to the left and the lower half goes to the right of the original terminal. An \fBANSI\fP terminal is emulated. -Neither program takes any options. -All arguments are forwarded to the called program. -While \fBtcvt\fP splits does this conversion unconditionally, the \fBoptcvt\fP can be used with smaller terminals. +While \fBtcvt\fP does this conversion unconditionally, the \fBoptcvt\fP can be used with smaller terminals. It will only invoke \fBtcvt\fP, if the terminal is wide enough and otherwise simply exec the passed program. +.Sh OPTIONS +Both programs take a program and options to that program. +They execute the given program. +If no program is given a shell is executed. + +In addition the \fBtcvt\fP tool accepts a few switches. +.Bl -tag -width indent +.It Fl c , Fl Fl columns +Specify the number of columns. This defaults to two. +.It Fl h , Fl Fl help +Print a quick option overview and exit. +.It Fl Fl +Signal end of options. +.El + +Any non-option argument signals the end of options for \fBtcvt\fP. .Sh BUGS Not all \fBANSI\fP terminal features are emulated. If you experience rendering issues, you can export the environment variable \fBTCVT_DEVEL\fP. @@ -39,6 +39,7 @@ import struct import curses import errno import time +import optparse def init_color_pairs(): for bi, bc in enumerate((curses.COLOR_BLACK, curses.COLOR_RED, @@ -292,7 +293,7 @@ def compose_dicts(dct1, dct2): return result class Terminal: - def __init__(self, acsc): + def __init__(self, acsc, columns): self.mode = (self.feed_simple,) self.realscreen = None self.screen = None @@ -300,12 +301,13 @@ class Terminal: self.graphics_font = False self.graphics_chars = acsc # really initialized after self.lastchar = ord(b' ') + self.columns = columns def switchmode(self): if isinstance(self.screen, Columns): self.screen = Simple(self.realscreen) else: - self.screen = Columns(self.realscreen) + self.screen = Columns(self.realscreen, self.columns) self.screen.refresh() def resized(self): @@ -327,7 +329,7 @@ class Terminal: self.realscreen.keypad(1) curses.start_color() init_color_pairs() - self.screen = Columns(self.realscreen) + self.screen = Columns(self.realscreen, self.columns) curses.noecho() curses.raw() self.graphics_chars = compose_dicts(self.graphics_chars, acs_map()) @@ -535,8 +537,13 @@ def set_cloexec(fd): fcntl.fcntl(fd, fcntl.F_SETFD, flags) def main(): + parser = optparse.OptionParser() + parser.disable_interspersed_args() + parser.add_option("-c", "--columns", dest="columns", metavar="N", + type="int", default=2, help="number of columns") + options, args = parser.parse_args() keymapping, acsc = compute_keymap(symbolic_keymapping) - t = Terminal(acsc) + t = Terminal(acsc, options.columns) errpiper, errpipew = os.pipe() set_cloexec(errpipew) @@ -545,10 +552,10 @@ def main(): os.close(errpiper) os.environ["TERM"] = "ansi" try: - if len(sys.argv) < 2: + if len(args) < 1: os.execvp(os.environ["SHELL"], [os.environ["SHELL"]]) else: - os.execvp(sys.argv[1], sys.argv[1:]) + os.execvp(args[0], args) except OSError as err: os.write(errpipew, "exec failed: %s" % (err,)) sys.exit(1) |