diff --git a/ok-show.py b/ok-show.py index 12843bb..68b04a8 100755 --- a/ok-show.py +++ b/ok-show.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from __future__ import print_function -import argparse, codecs, os, re, sys +import argparse, codecs, os, re, shutil, sys def ansi_len(s): no_ansi_s = rx.ansi_len.sub('', s) @@ -130,12 +130,12 @@ def print_line(l, clr, nr_positions_line_nr, format_line): def main(): # customizations clr = ok_color() - + terminal_size = shutil.get_terminal_size() # handle arguments parser = argparse.ArgumentParser(description='Show the ok-file colorized (or just one line).') parser.add_argument('--verbose', '-v', metavar='V', type=int, default=1, help='0=quiet, 1=normal, 2=verbose. Defaults to 1. ') parser.add_argument('--comment_align', '-c', metavar='CA', type=int, default=2, choices= [0,1,2,3], help='Level ($e) of comment alignment. 0=no alignment, 1=align consecutive lines (Default), 2=including whitespace, 3 align all.') - parser.add_argument('--terminal_width', '-t', metavar='TW', type=int, default=230, help='number of columns of the terminal (tput cols)') + parser.add_argument('--terminal_width', '-t', metavar='TW', type=int, default=terminal_size.columns, help='number of columns of the terminal (tput cols)') parser.add_argument('only_line_nr', metavar='N', type=int, nargs='?', help='the line number to show') args = parser.parse_args() diff --git a/ok.sh b/ok.sh index b5ec82d..06d8685 100755 --- a/ok.sh +++ b/ok.sh @@ -73,7 +73,7 @@ environment variables (for internal use): shift # get the line to be executed local line_text - line_text="$(cat "$ok_file" | "$_OK__PATH_TO_PYTHON" "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" -t "$(tput cols)" "$line_nr")" + line_text="$(cat "$ok_file" | "$_OK__PATH_TO_PYTHON" "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" "$line_nr")" local res=$? if [[ $res -ne 0 ]]; then #because stdout/stderr are swapped by ok-show.py in this case, handle this too @@ -86,7 +86,7 @@ environment variables (for internal use): function _ok_cmd_list { unset -f _ok_cmd_list - cat "$ok_file" | "$_OK__PATH_TO_PYTHON" "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" -t "$(tput cols)" || return $? + cat "$ok_file" | "$_OK__PATH_TO_PYTHON" "${_OK__PATH_TO_ME}/ok-show.py" -v "$verbose" -c "$comment_align" || return $? } # export variables because python is a sub-process, and variables might have changed since initialization @@ -97,8 +97,8 @@ environment variables (for internal use): local -r version="0.8.0" # used for colored output (see: https://stackoverflow.com/a/20983251/56) # notice: this is partly a duplication from code in ok-show.py - local -r c_nc=$(tput sgr0) - if [ -z ${_OK_C_NUMBER+x} ]; then local c_number=$(tput setaf 6); else local c_number=$_OK_C_NUMBER; fi #NUMBER defaults to CYAN + local -r c_nc='\[\e[0m\]' + if [ -z ${_OK_C_NUMBER+x} ]; then local c_number='\[\e[0;36m\]'; else local c_number=$_OK_C_NUMBER; fi #NUMBER defaults to CYAN if [ -z ${_OK_C_PROMPT+x} ]; then local c_prompt=$c_number; else local c_prompt=$_OK_C_PROMPT; fi #PROMPT defaults to same color as NUMBER # other customizations (some environment variables can be overridden by arguments) if [ -z ${_OK_PROMPT+x} ]; then local prompt="$ "; else local prompt=$_OK_PROMPT; fi