summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xoptcvt.sh2
-rw-r--r--tcvt.122
-rwxr-xr-xtcvt.py19
3 files changed, 33 insertions, 10 deletions
diff --git a/optcvt.sh b/optcvt.sh
index 2f3f89c..b73c095 100755
--- a/optcvt.sh
+++ b/optcvt.sh
@@ -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
diff --git a/tcvt.1 b/tcvt.1
index 80bb803..dd0e272 100644
--- a/tcvt.1
+++ b/tcvt.1
@@ -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.
diff --git a/tcvt.py b/tcvt.py
index 590b111..4393cfb 100755
--- a/tcvt.py
+++ b/tcvt.py
@@ -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)