DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 24th December 2020
sabrina sabrina is offline
Port Guard
 
Join Date: Jun 2020
Posts: 15
Question xterm-256color and setaf question

Hello! I need help to figure out how tput setaf works on xterm-256color!
If TERM=xterm, then tput setaf 1 works and changes foreground color to red, but it only supports 8 colors. If TERM=xterm-256color, then tput setaf 1 fails with error
Code:
tput: not enough arguments (3) for capability `setaf'
What need to be done to make tput setaf work on xterm-256color?
Thank you!
Reply With Quote
  #2   (View Single Post)  
Old 24th December 2020
sabrina sabrina is offline
Port Guard
 
Join Date: Jun 2020
Posts: 15
Default

Code:
tput bold cup 5 22 setaf 1 smso;print MENU;tput sgr0
This code works, if TERM=xterm, but fails if TERM=xterm-256color.
Reply With Quote
  #3   (View Single Post)  
Old 24th December 2020
fvgit's Avatar
fvgit fvgit is offline
Spikes in tights
 
Join Date: May 2016
Location: perl -MMIME::Base64 -le 'print decode_base64("U2hlcndvb2QgRm9yZXN0")'
Posts: 314
Default

I can't give you an explanation as to the why, but I can show you how to make it work if you really need to use xterm-256color.

BTW, xterm-16color, xterm-88color, and tmux-256color exhibit the same behaviour, whereas your example works without any problems if you use xterm-vt220, tmux, or xterm-color for instance.

Anyway, the error message indicates that you're missing an argument to the setaf capability. So you need to provice a third argument. Try this:
Code:
tput bold cup 5 22 setaf 1 1 smso;print Merry Christmas;tput sgr0
Note the extra argument in red between 1 and smso. It doesn't seem to matter what I put there, but it keeps tput happy.
Reply With Quote
  #4   (View Single Post)  
Old 24th December 2020
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 465
Default

Raw ANSI escape codes also work:
Code:
printf '\033[38;5;196mBah Humbug!\033[0m\n'
https://gist.github.com/fnky/4587193...797#256-colors
__________________
Are you infected with Wetiko?
Reply With Quote
  #5   (View Single Post)  
Old 24th December 2020
sabrina sabrina is offline
Port Guard
 
Join Date: Jun 2020
Posts: 15
Red face

Thank you, indeed xterm-256color requires 3 arguments for setaf: tput setaf 1 1 1. Still I would like to know the meaning of those 3 arguments.
Here is my little Christmas ksh script:
Code:
#!/bin/ksh

tput clear
tempterm=$TERM
TERM=xterm-256color
num=22
set -A chararray M e r r y ' ' C h r i s t m a s \!
for i in $(jot 16 34 104)
do
    tput bold smso cup 5 $(( num++ )) setaf $i 1 1
    printf "${chararray[num-23]}"
    tput sgr0
done
print
TERM=$tempterm
To see all 256 colors I use:
Code:
printf '\e[48;5;%dm ' $(jot 256 0); printf '\e[0m \n'
Reply With Quote
  #6   (View Single Post)  
Old 30th December 2020
fvgit's Avatar
fvgit fvgit is offline
Spikes in tights
 
Join Date: May 2016
Location: perl -MMIME::Base64 -le 'print decode_base64("U2hlcndvb2QgRm9yZXN0")'
Posts: 314
Default

Nice script!

The weird thing about those extra setaf arguments is that although they seem to be required, they get ignored:

This works for me:
Code:
tput bold cup 5 22 setaf 1 Bah, Humbug;print Merry Christmas;tput sgr0
as does this
Code:
tput bold cup 5 22 setaf 1 rm /bsd;print Merry Christmas;tput sgr0
Obviously the rm /bsd throws no "override... Permission denied" dialogue since it gets ignored.

Kids, don't try this at home! Some arguments to the rm(1) command will get through and depending on the target there will be tears.

I may not have looked hard enough, but the setaf thingie seems underdocumented in OpenBSD. Strange.
Reply With Quote
  #7   (View Single Post)  
Old 30th December 2020
sabrina sabrina is offline
Port Guard
 
Join Date: Jun 2020
Posts: 15
Lightbulb

Hello!
I've found the answer: setaf if bugged in the version of ncurses OpenBSD using. Setaf behavior is fixed in the latest version of ncurses.
With TERM=xterm, I set this nice looking prompt in my .kshrc
Code:
PS1='\[$(tput smso setaf 3)\]\W\[$(tput rmso op)\]:\!:\[$(tput setaf 1)\]\$\[$(tput op)\] '

Last edited by sabrina; 30th December 2020 at 05:37 AM. Reason: fixed PS1 string
Reply With Quote
  #8   (View Single Post)  
Old 30th December 2020
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,983
Default

Please consider reporting the bug.
Reply With Quote
  #9   (View Single Post)  
Old 31st December 2020
sabrina sabrina is offline
Port Guard
 
Join Date: Jun 2020
Posts: 15
Default

Hello!
I have sent the bug report.
Reply With Quote
Old 2nd January 2021
sabrina sabrina is offline
Port Guard
 
Join Date: Jun 2020
Posts: 15
Thumbs up

Hello!
I received answers from mailing list.
Short summary:
OpenBSD uses version of ncurses from 11 years ago, modified with local changes.
OpenBSD's tput is not from ncurses, it validates the number of arguments separately and that doesn't match what's actually needed by ncurses.
Workaround: use anything for the 2nd and 3rd parameters, both the OpenBSD and ncurses tput commands ignore these. e.g. tput setaf 1 1 1.
Reply With Quote
Reply

Tags
xterm tput setaf 256color


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenBSD xterm(1) now UTF-8 by default J65nko News 1 10th March 2016 07:22 PM
Getting console messages in xterm? spiderpig OpenBSD General 1 30th August 2015 12:17 AM
xterm is not a login shell except on blackbox daemonfowl NetBSD General 6 1st August 2012 03:59 AM
is there a way to cut and paste text from xterm ? daemonfowl OpenBSD General 6 30th January 2012 08:03 PM
xterm End key graudeejs General software and network 1 24th August 2008 04:55 PM


All times are GMT. The time now is 08:54 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick