Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

increase default code-len window

by perl-diddler (Chaplain)
on Sep 18, 2013 at 18:36 UTC ( [id://1054719]=monkdiscuss: print w/replies, xml ) Need Help??

I try to make a point to change my tabs to spaces before I copy over code, but I notice that code that fits in a standard 80-wide tty-size window still wraps. it seems to wrap at 70 columns, yet width-wise, it only takes the left 2/3rds of the column.

Is it possible to make the width of that be at least a standard 80 chars? Better -- would be a settable width in user options and the option of whether to wrap it on display or provide a horizontal scroll bar...

But the 80 char-wide default window seems like it would be really useful, since that's the lowest normal size terminal width. Is that possible?

Replies are listed 'Best First'.
Re: increase default code-len window (no)
by Anonymous Monk on Sep 18, 2013 at 22:40 UTC
    code wrap length is configurable through User Settings, so go forth and configure
Re: increase default code-len window
by boftx (Deacon) on Sep 19, 2013 at 06:00 UTC

    I would wager that a significant portion of "programmers" today (especially those who do not code in Perl or C on a *nix platform) have no idea why 80 columns is a magic number. (Hint: it is not because of the VT100 terminal.)

      Could it possibly be due to punch cards? Or did Fortran precede punch cards?

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        Yes, FORTRAN (introduced in 1957) was originally written on 80-column punch cards:

        Before the development of disk files, text editors and terminals, programs were most often entered on a keypunch keyboard onto 80 column punched cards, one line to a card. The resulting deck of cards would be fed into a card reader to be compiled....
        Originally Fortran programs were written in a fixed column format.... the card was divided into four fields. Columns 1 to 5 were the label field: a sequence of digits here was taken as a label for the purpose of a GOTO or a FORMAT reference in a WRITE or READ statement. Column 6 was a continuation field: a non-blank character here caused the card to be taken as a continuation of the statement on the previous card. Columns 7 to 72 served as the statement field. Columns 73 to 80 were ignored, so they could be used for identification information.
        Wikipedia, “Fortran”

        So,

        A legacy of the 80 column punched card format is that a display of 80 characters per row was a common choice in the design of character-based terminals.
        Wikipedia, “Punched_card”

        See also Wikipedia, “Characters per line”.

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: increase default code-len window
by Happy-the-monk (Canon) on Sep 18, 2013 at 18:40 UTC

    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)

      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? ;-)

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://1054719]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-24 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found