Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: increase default code-len window

by Happy-the-monk (Canon)
on Sep 18, 2013 at 18:40 UTC ( #1054721=note: print w/replies, xml ) Need Help??

in reply to increase default code-len window

Update: my big oopsie here - I dreamt this post into the Seekers Of Perl Wisdom section and saw an intriguing GUI discussion coming up.

I understand what's meant now, sorry, sorry.

I hadn't measured where lines break in <code> sections -- but 80 characters as you suggest seem very reasonable to me.

My original stupid rambling below:

What's Perl got to do with terminal windows? Where does it come into your train of thought? (since you don't mention it)

Cheers, Sören

Créateur des bugs mobiles - let loose once, run everywhere.
(hooked on the Perl Programming language)

Replies are listed 'Best First'.
Re^2: increase default code-len window
by perl-diddler (Hermit) on Sep 19, 2013 at 02:50 UTC
    Responding to your GUI item... ;-)

    Perl is more often run on a terminal of "some sort", than under some form of GUI (vs. visual basic, or maybe Java) as well as more often than in a local browser window where output like javascript is seen.

    Of the few GUI interfaces that work (for some value of work) for perl, they seem to be "tty-oriented" (fixed fonts, seem more common for most prog tasks). Don't know of any that use much in the way of bitmapped, vector or 3D graphics...

    One thing that is notable among most of the tty-type display (mostly terminal emulators running in a window)... MOST of them have EMCA-48 (vt100/linux console) level support & compatibility including various levels of color support (at least 16, usually 256, some have more), and nearly all have variable tabstops. Of course nearly NO ONE actually uses the variable tabstops and many would like "council that you shouldn't change the hardware tab stop because "bad things will happen" or some such mumbo jumbo -- but won't be able to give any concrete examples because it's not worth their time, but .. perl trace-backs and error messages fit on an 80-column wide screen much more easily when a tab=2.5% of window width instead of the default 10% window width.

    The nice thing about using tabs is if you use ALL tabs in your program for indentation and don't mix your white space, is that the tabs can be set on a per/user-choice basis -- and no changing of the code is needed. Whether you like 4, 3, 6, 2, or 8, you can change the tabs in such a program and it will continue with consistent indenting (except where you also wanted things to line up based on some specified tab-expansion value.

    But setting and using the tabs at different values is a PITA, right?

    Not really... set your editor-rc, and text-pager (less).. and have the tabs set to your desired value on login with a convenient shell script.

    It's not really perl, but I add aliases in my shell coding to make it a bit more friendly, but I made sure to include everything in one file (since I don't really know of a CBAN to distribute them, anyway)...;-)

    #!/bin/bash -u #console_codes(4) man page... vt100/2 et && EMCA-48 standard # (c) la walsh (2013) -- free to use and modify for personal use. # -- optionally licenced under Gnu v3 license. # v0.0.3 - try to reduce tabcols to minimal set to reproduce. # v0.0.2 - set tabs for full terminal width (try to get term width) shopt -s expand_aliases extglob alias int='declare -i' sub='function' array='declare -a' alias intArray='declare -ia' P=printf string=declare P -v clrallts "\x1b[3g" P -v sts "\033H" P -v cpr "\x1b[6n" sub getcols() { local sttyout="$(stty size </dev/tty)" int default_cols=80 if [[ -n ${COLUMNS:-""} && $COLUMNS =~ ^[0-9]+$ ]]; then default_cols=$COLUMNS; fi [[ -z ${sttyout:-""} ]] && { echo $default_cols; return 0; } int cols="${sttyout#*\ }" echo -n $[cols<2?default_cols:cols] return 0 } sub getpos () { string ans wanted=${1:-xy} int attempt=0 max_attempt=1 # in case of rare failure case # use 'attempt' value as additional # time to wait for response while : ; do ( ( P "\x1b[6n" >/dev/tty) & 2>/dev/null ) read -sd R -r -t $[2 + attempt] ans </dev/tty; ans=${ans:2}; int x=0-1 y=0-1 if ! x="${ans#*;}" y="${ans%;*}" 2>/dev/null || ((x==-1||y==-1)); then ((attempt+=1 < max_attempt)) && continue fi break; done string out="" [[ $wanted =~ x ]] && out="$x" [[ $wanted =~ y ]] && out="${out:+$x }$y" [[ $out ]] && echo -n "$out" } declare -iga tabs sub get_tabs () { P "\r" tabs=() int pos=0 oldpos=0-1 while ((oldpos!=pos));do ((pos)) && tabs+=($pos) oldpos=pos P "\t" pos=$(getpos x) done P "\r" return 0 } # Note: this sub uses ability to _read_ tabstops as _proxy_ for settin +g them # (i.e. it makes no sense to be able to read them if you can't set the +m) sub test_tabset_ability () { string prompt="tty_tab:" int newcol=${#prompt}+1 P "\r$prompt" int mycol=$(getpos x) ((mycol && mycol==newcol)) && return 0 ## return OK { P " Term tabset ability not detected mycol=${mycol:-''}," P " promptlen=$newcol)\n"; } >&2 exit -1 } sub do_help_n_display_curtabs () { P " <n> - set tab stop to N\r" intArray diffs; int last=1 cur i string eol="" get_tabs && { for ((i=0; i<${#tabs[@]}; ++i)); do cur=${tabs[i]} diffs[i]=cur-last last=cur done intArray reverse_tabs_set=() int prevtab=0-1 for ((i=${#diffs[@]}-2; i>0; --i)); do int thistab=${diffs[i]} if ((thistab!= prevtab)) ;then reverse_tabs_set+=($thistab) prevtab=thistab fi done P "current value: tty_tab " for ((i=${#reverse_tabs_set[@]}-1; i>=0; --i)); do P "%d " "${reverse_tabs_set[i]}"; done P "\r"; } get_tabs && { P "(from 1, tabs skip to column: " P "%s " "${tabs[@]}" P "\r\n" } } sub set_tabs () { int max_col=${1:-80} tabstop=${2:-"need a param for tabstop"} int tab=$tabstop pos=0 string str="" P $clrallts ## reset old tabs while ((++pos<cols)) ;do ## move across screen setting tabs str+=" " ((pos%tab)) || str+="$sts" done P "\r$str\r" } int cols=$(getcols) test_tabset_ability ## exits if no ability if (($#==0)) ; then do_help_n_display_curtabs exit 1 else set_tabs "$cols" "$@" fi # vim: ts=2 sw=2

    In my .bashrc, I call it with "2" as a param: "tty_tab 2; echo -en "\r".

    I think if more people knew how easy it was to reset their tabs, it might increase usage by almost 2%! ;-)

    Admit it -- have you ever seen "shell" look so perlish? ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1054721]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-05-26 22:41 GMT
Find Nodes?
    Voting Booth?