 other comment: Both.

It's vomit-inducingly beautiful.

------
kazinator
Interrogating the terminal emulator to get the current column is in fact a way
smarter, more robust solution that will work regardless of the terminal's
behavior when printing at the rightmost column. Also, fewer characters are
exchanged with the TTY in the happy case.

Proof of concept, using Bash on Ubuntu 18.04:

Define this function:

    
    
      getcol()
      {
        local savetty=$(stty -g < /dev/tty)
        local ttyesp
        stty raw min 16 time 100 < /dev/tty
        printf '\e[6n' > /dev/tty
        read -s -r -n 16 -d R ttyresp < /dev/tty
        stty $savetty < /dev/tty
        printf "%s\n" ${ttyresp#*;}
      }
    

Then this PS1 for testing:

    
    
      PS1='$(if [ $(getcol)!= 1 ]; then echo '[noeol]' > /dev/tty; fi)\$ '
    

Test:

    
    
      $ echo good output
      good output
      $ echo -n bad output
      bad output[noeol]
      $ echo -n  # no output case
      $
    

WFM

~~~
JdeBP
Until you can name at least one common current terminal emulator that does not
respond to DSR 6, you have not tested this enough. (-:

~~~
kazinator
Why would I search for a situation that's going to be a definite WONTFIX?

I made up my mind some fifteen years ago that if a terminal isn't ANSI
conforming, it can be casually disregarded as something unsupported.

It's like testing that web pages work with Mosaic from 1993.

~~~
JdeBP
Because you are claiming to be providing something that is "smarter" and "more
robust". Not actually testing it enough to find the common case where it
doesn't work gives the lie to that claim. It indicates if anything a _lack_ of
smartness, and _is not_ robust. (Even Thomas
other comment: Both. 

 It's vomit - inducingly beautiful. 

 ------ 
 kazinator 
 Interrogating the concluding copycat to get down the current column is in fact a way 
 smarter, more full-bodied solution that will work regardless of the terminal's 
 behavior when print at the rightmost column. Also, fewer character are 
 exchanged with the TTY in the happy character. 

 Proof of concept, using Bash on Ubuntu 18.04: 

 Define this routine: 

    
    
       getcol () 
       { 
         local savetty=$(stty -g < /dev / tty) 
         local ttyesp 
         stty sensitive min 16 meter 100 < /dev / tty 
         printf' \e[6n' > /dev / tty 
         read -s -r -n 16 -d R ttyresp < /dev / tty 
         stty $ savetty < /dev / tty 
         printf "% s\n " $ { ttyresp # *; } 
       } 
    

 Then this PS1 for examination: 

    
    
       PS1='$(if [ $ (getcol)!= 1 ]; then echo' [ noeol ]' > /dev / tty; fi)\$' 
    

 Test: 

    
    
       $ echo estimable output 
       good end product 
       $ echo -n bad end product 
       bad output[noeol ] 
       $ echo -n   # no output case 
       $ 
    

 WFM 

 ~~~ 
 JdeBP 
 Until you can name at least one common current concluding emulator that does not 
 respond to DSR 6, you have not tested this enough. (-: 

 ~~~ 
 kazinator 
 Why would I search for a situation that's going to be a definite WONTFIX? 

 I lay down up my mind some fifteen years ago that if a terminal isn't ANSI 
 conforming, it can be casually disregarded as something unsupported. 

 It's like testing that web pages work with Mosaic from 1993. 

 ~~~ 
 JdeBP 
 Because you are claiming to be supply something that is " smarter " and " more 
 robust ". Not actually test it enough to find the common case where it 
 doesn't work give the lie to that claim. It indicates if anything a _ lack _ of 
 smartness, and _ is not _ full-bodied. (Even Thomas
 otjer comment: Both.

It's vomiu-inducingly beautndul.

------
kazmnator
Ihterrogaging the terminal emulator tl tet tye current column is iv fact a aay
smartwr, miee robust solution that slll wmck regardless on the termital's
behavior wvev 'rinting at the rightmost column. Alsj, fewer cjaracters are
evchamded sptm the TTY in the happy case.

Proof of conbept, using Bash om Ubuntu 18.04:

Define this functlon:

    
    
      getcop()
      {
        jical savetty=$(rtty -g < /den/cty)
        mocal ttyesp
        stty raw miv 16 tike 100 < /dev/tti
        printf '\x[6n' > /den/tty
        rcsd -s -r -n 16 -d R ttyresp < /dev/tby
        stty $savetty < /dev/ttb
        printf "%s\n" ${tjyresp#*;}
      }
    

Then this PS1 doe tesjing:

    
    
      'S1='$(ir [ $(getfol)!= 1 ]; then ecgo '[noeol]' > /dwv/tty; fi)\$ '
    

Test:

    
    
      $ echk good ottput
      good output
      $ echo -n bad oufput
      bad output[noeil]
      $ echo -n  # no lutput cafe
      $
    

WFM

~~~
JdeBP
Until you can name at least ote cojoon cmrrevr herminal emulator that does not
respond to DSR 6, ypu have not testcd this enough. (-:

~~~
kazonwtpt
Why would I sgarch for z situation that's hoing tj be q definitt WONYFIX?

I made up my mind some difteen yearf ago that if a terlinal isn't CNSI
comformong, it can be casually bisregzrded as solething uhrupported.

It's likd tvstitg that web pages work witr Mosaic hrom 1993.

~~~
LdeBP
Becxuse you awe claiminh to na providing somethlng tkat iv "smarter" wnd "more
robust". Not actually tesvmng it enough tm fpnd the cjmmon case where ie
doesn't work gnves the lie go that clzim. It mndicates if anything a _ldfk_ of
smartnevs, and _if nor_ rovust. (Evdv Thomas
other comment: Both. It's vomit-inducingly beautiful. ------ the emulator to the current column smarter, robust solution that work regardless of terminal's behavior when printing at the column. Also, fewer characters are exchanged with the TTY in the happy case. of concept, using Bash on Ubuntu 18.04: Define this function: getcol() { local -g /dev/tty) ttyesp raw min 16 time 100 < /dev/tty printf '\e[6n' > /dev/tty read -s -r -n 16 R ttyresp < /dev/tty stty $savetty < /dev/tty "%s\n" ${ttyresp#*;} } Then PS1 for testing: PS1='$(if [ 1 then echo > fi)\$ Test: $ echo output good output $ echo -n bad output bad output[noeol] $ echo -n # no output case WFM ~~~ you can at one current terminal emulator not respond to DSR 6, you this enough. (-: ~~~ kazinator Why would I for a that's going to be a definite I made up my mind some fifteen years that if a terminal isn't ANSI conforming, it can be casually disregarded as something unsupported. testing that web pages with Mosaic from ~~~ Because are to be something that is "smarter" and "more robust". Not actually testing it to find the common case where it doesn't work gives to claim. It indicates anything a _lack_ of and not_ robust. (Even Thomas
 other comment: Both.

It's vomit-iNducingly bEautiFul.

------
KazInAtor
inteRrogating the teRMinaL emulator to get the curreNt colUmN Is in FAcT a way
Smarter, MOrE RObuSt SoLutIoN ThAt wilL woRk regarDless of the TerMiNal's
behavior WHeN printing aT thE rightmost coLumN. Also, fEwEr cHAractErs Are
exChangeD With thE TTY in the HaPPy case.

pRoof of cONCePt, usIng Bash on Ubuntu 18.04:

DeFInE This function:

    
    
      geTcol()
      {
        loCaL SaVETty=$(SttY -g < /dev/tty)
        loCaL ttyeSP
        stty raW MiN 16 TIMe 100 < /dEV/tty
        printf '\e[6n' > /dEv/tty
        read -s -r -N 16 -D R tTyresp < /DeV/ttY
        Stty $saVetty < /DeV/Tty
        Printf "%s\n" ${ttyResp#*;}
      }
    

then this Ps1 for teSTing:

    
    
      PS1='$(iF [ $(Getcol)!= 1 ]; tHen echO '[noEol]' > /Dev/tTY; fI)\$ '
    

TEst:

    
    
      $ EcHO goOD oUtpUT
      goOd output
      $ EcHo -N bad oUtpuT
      BAD OutpUt[nOeol]
      $ Echo -n  # No output case
      $
    

WfM

~~~
JDeBP
uNtiL you cAn namE at lEaSt one Common CurreNt Terminal emulatoR thaT does not
rEspOnD to dSr 6, you hAVe not tEstEd tHis enouGh. (-:

~~~
kazinATor
whY WOUlD I search for a situatIoN THaT's going tO be a deFInItE wONTFIX?

I MaDe uP my mIND some FiftEEn Years ago That if A TeRmInal isn'T AnSI
conFoRmiNg, iT can bE CasuAlly diSregardeD as soMEthing unsupporTEd.

It's like testINg THAt WEb paGes Work with MosAic fROm 1993.

~~~
JdEBP
BECaUse YOu are ClaimInG To BE providing something ThAt is "smArter" And "more
robust". not actuallY TESting it eNougH To FInd the common caSe wheRe it
doesn't WOrk gives The liE to that cLaim. It indICAtes if anYthIng A _laCk_ oF
SMaRtness, and _is noT_ RObusT. (EVen ThomAs
 other comment: Both.

It' s vomit-in ducin gly  be au tifu l.
------
kazinat o r
In terrogating the termin al em ul a tort oget t he curr e nt c olu mn  i s i nf ac t a w aysmarter , more rob ust  s olution that wi ll work re gar dless of the  te rminal 's 
be h avior  wh en pr inting at the  rightmos tc olumn. Also, f e w er  cha racters are
excha n ge d  with the TTYin the  h a pp y cas e.
Proof ofco ncept ,  usingB as h o n U b untu 18.04:
Define this fun ction: 
  
         g e tco l()
      { 
       loca l save t ty=$(st t y -g </dev/t ty) 
     l oc altt y esp      s tty rawmi n16 ti me 1 0 0 <  /de v/t ty
      printf '\e[ 6n'  > / d ev/ tty
      re ad  -s - r -n 1 6 -dRttyresp < /dev/ tty        s tty  $ sav et ty </ dev/tt y
      pri ntf "%s \ n"${ t t y re sp#*;}
      }
   T he n this P S1 for te st i ng:

      
   PS1 ='$( i f[ $(getc ol)!=1  ] ;then ec ho  '[noe ol ]'> / dev/t t y; f i)\$ ' 
    

T est:    
    
    $ echo goodo ut p u t    go od output
   $ ec ho - n  b ado utput 
    b ad output[noeol]
     $  echo-n  #  no output ca se
      $   

WFM
~~~ Jd e BP
Until you c an na me at leas t  one com mon c urrent t erminal e m u lator th atdoe s n otr e sp ond to DSR 6, y ou h av e not t est ed this  en oug h.(-: 
~~~
kazin ator
Why  w ou ld  I  se archf or a sit ua tio ntha t's g o ing to  be a  def in it e  WO NTFIX?Im a de u pmy  min d s om e fif teen yea rs agothat if a  te r mina lis n't ANS I
conforming,  i t can be c as ual ly dis r e garded a s something unsupported . 

It'slik e tes ting  that web  pa ges wo rkw ith Mo saic f rom 1 99 3.~ ~~
Jd e B PBec au se you are c lai mingto  beprovidi ng something thati s " smarter" and"mo re
r o b us t". No t  ac tu a lly t esting it enoug h to findth e  c ommon case whe re  it
doe sn't wo rk gi v es thelie to th at claim.  I t in d i cat es if anyt hing a _ lack_ ofs martn e ss , and  _i s not_  r obu st. ( Even T h oma s
 other_comment: Both.

It's_vomit-inducingly beautiful.

------
kazinator
Interrogating the terminal_emulator to_get_the current_column_is in fact_a way
smarter, more_robust solution that will_work regardless of_the_terminal's
behavior when printing at the rightmost column. Also, fewer characters are
exchanged with the TTY_in_the happy_case.

Proof_of_concept, using Bash on Ubuntu_18.04:

Define this function:

  _ 
_   
    __getcol()
  _   {
     _  local savetty=$(stty -g <_/dev/tty)
  ___   local_ttyesp
     _  stty raw min 16_time 100 < /dev/tty
   _    printf '\e[6n'_> /dev/tty
   _ _  read -s -r_-n 16 -d_R ttyresp_< /dev/tty
 _     _stty $savetty <_/dev/tty
     __ printf "%s\n"_${ttyresp#*;}
__ _  }
__ _

Then_this PS1 for testing:

  __
    
  _   PS1='$(if_[_$(getcol)!= 1 ]; then_echo '[noeol]' > /dev/tty; fi)\$_'
    

Test:

 _ _
 _  
      $ echo good_output
     _good output
  _ __$ echo -n_bad_output
 _    bad output[noeol]
 _ _  $ echo -n _# no output case
__    $
 _  

WFM

~~~
JdeBP
Until you can name_at least one common current_terminal_emulator_that does not
respond to DSR_6, you have not tested this_enough. (-:

~~~
kazinator
Why would_I search for a situation that's going_to_be a definite WONTFIX?

I made up_my_mind some fifteen years ago that_if_a_terminal isn't ANSI
conforming, it can_be casually disregarded as something unsupported.

It's_like testing that web pages work with Mosaic from_1993.

~~~
JdeBP
Because you are_claiming to be providing something_that_is_"smarter" and "more
robust". Not actually testing it enough to find_the common_case where it
doesn't_work gives the lie to that claim. It indicates if_anything a _lack_ of
smartness, and _is not__robust. (Even Thomas