Bug 80725 - wish: colour in tabbar text
Summary: wish: colour in tabbar text
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Mandrake RPMs Linux
: NOR wishlist
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-01 07:23 UTC by Richard Neill
Modified: 2019-03-09 09:01 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Neill 2004-05-01 07:23:44 UTC
Version:            (using KDE KDE 3.2.0)
Installed from:    Mandrake RPMs

I have the  following in my .bashrc, which is great for renaming the icons in the konsole tab bar.

if test "$DISPLAY"; then
        export PROMPT_COMMAND='echo -ne "\033]30;`basename "$PWD"`/ \007\033]31;\007"'
fi


but ideally, I'd like to make this coloured. (Eg to add a red * when root) Could we have support for colour?
(I tried the standard shell colour escape codes, without success).


Also, it would be nice if this were documented in the konsole manual (I know it is in one of the startup tips), and if there were some sort of GUI for it. For example, I'd use:

local machine, directory is /home/me/foo/bar           ->     bar/
local machine, directory is /home/me/baz, as root      ->     *baz/  (the * is in red)
remote machine, called mocha, directory /home/me       ->     mocha:me/
database (psql -U DB_NAME)                             ->     DB_NAME
Comment 1 Kurt Hindenburg 2005-01-04 16:25:16 UTC
Why are you using PROMPT_COMMAND and not PS1?
Anyway, you can put colors in PS1.  Check out the bash help or google.  This is not really konsole related.

Here's a snippet of my .bashrc:

COLOR1="\[\033[0;36m\]"
COLOR2="\[\033[0;32m\]"
COLOR3="\[\033[0;31m\]"
COLOR4="\[\033[0;37m\]"
COLOR5="\[\033[1;32m\]"
COLOR6="\[\033[1;34m\]"

PS1="$COLOR2($COLOR6\u$COLOR5@$COLOR6\h$COLOR2)-($COLOR1\$(date +%H%M)$COLOR2)-($COLOR1\w$COLOR2)$COLOR1>$COLOR4 "
if [ "$TERM" != 'linux' ]; then
   PS1=$PS1"\[\e]30;\w\a\]"
fi
export PS1
Comment 2 Richard Neill 2005-01-05 01:35:23 UTC
I'm sorry, that wasn't what I meant, and what I wrote wasn't very clear. I do realise that you can colorise the bash prompt itself (and I've done this). However, what I am trying to colorise is the names in the toolbar of konsole. 

For example, if I have 10 different sessions open, all listed in the toolbar at the bottom of the konsole window, I'd like those where I am root to be highlighted in red, so that they can easily be located. [Perhaps, remote sessions would be in blue and database connections in green]. 

Also, I'm using PROMPT_COMMAND because that was originally the way it was documented; although I see that PS1 might make more sense.

Thanks for your help - and Happy New Year.
Comment 3 Kurt Hindenburg 2005-01-05 07:10:08 UTC
You can change the icon for each session.  Currently, su is red icon and mc is blue icon.  You can;t change the color of the tab text which is what you really want.  I would suggest change the tab text to something descriptive for what that shell is doing.  Perhaps * for root and + for ssh, etc.... this can be done via DCOP calls...

dcop konsole-8507 session-1 renameSession whatever

or by using some combo of...


..that you can let Konsole set the current directory as the window title?
For Bash, put 'export PS1=$PS1"\[\e]0;\H:\w\a\]"' in your ~/.bashrc .


...that you can let Konsole set the current directory as the session name?
For Bash, put 'export PS1=$PS1"\[\e]30;\H:\w\a\]"' in your ~/.bashrc .



Anyway, adding color to the tab text is unlikely anytime soon...
Comment 4 Kurt Hindenburg 2005-03-22 18:16:12 UTC
This was easier than I thought.  You still can't select the color via an escape code.  You have to right-click on the tab and select 'Select Tab Color...'

I really don't want to have an escape code for this; perhaps a DCOP call...
Comment 5 Kurt Hindenburg 2005-03-22 18:25:38 UTC
CVS commit by hindenburg: 

Allow user to select tab text color.

FEATURE: 80725
GUI


  M +13 -1     konsole.cpp   1.521
  M +3 -0      konsole.h   1.201
  M +3 -0      main.cpp   1.289


--- kdebase/konsole/konsole/konsole.cpp  #1.520:1.521
@@ -256,4 +256,5 @@ Konsole::Konsole(const char* name, int h
 ,sl_sessionShortCuts(0)
 ,s_workDir(workdir)
+,m_tabColor(QColor())
 {
   isRestored = b_inRestore;
@@ -1397,4 +1398,6 @@ void Konsole::saveProperties(KConfig* co
         key = QString("MasterMode%1").arg(counter);
         config->writeEntry(key, sessions.current()->isMasterMode());
+        key = QString("TabColor%1").arg(counter);
+        config->writeEntry(key, tabwidget->tabColor((sessions.current())->widget()));
 
         QString cwd=sessions.current()->getCwd();
@@ -1426,4 +1429,5 @@ void Konsole::saveProperties(KConfig* co
   config->writeEntry("DynamicTabHide", b_dynamicTabHide);
   config->writeEntry("AutoResizeTabs", b_autoResizeTabs);
+  config->writeEntry("TabColor", tabwidget->tabColor(se->widget()));
 
   if (se) {
@@ -1547,4 +1551,6 @@ void Konsole::readProperties(KConfig* co
       b_dynamicTabHide = config->readBoolEntry("DynamicTabHide", false);
       b_autoResizeTabs = config->readBoolEntry("AutoResizeTabs", false);
+      m_tabColor = config->readColorEntry("TabColor");
+      if ( !m_tabColor.isValid() ) m_tabColor = QColor( Qt::black );
    }
 
@@ -1778,5 +1784,5 @@ void Konsole::createSessionTab(TEWidget 
     break;
   }
-  tabwidget->setTabColor(widget, QColor(0, 0, 0));
+  tabwidget->setTabColor(widget, m_tabColor);
 }
 
@@ -2906,4 +2912,10 @@ void Konsole::initMasterMode(bool state)
 }
 
+void Konsole::initTabColor(QColor color)
+{
+  if ( !color.isValid() ) color = QColor( Qt::black );
+  tabwidget->setTabColor( se->widget(), color );
+}
+
 void Konsole::slotToggleMasterMode()
 {

--- kdebase/konsole/konsole/konsole.h  #1.200:1.201
@@ -82,4 +82,5 @@ public:
   void initMonitorSilence(bool on);
   void initMasterMode(bool on);
+  void initTabColor(QColor color);
   void newSession(const QString &program, const QStrList &args, const QString &term, const QString &icon, const QString &title, const QString &cwd);
   void setSchema(const QString & path);
@@ -420,4 +421,6 @@ private:
   QStringList    sl_sessionShortCuts;
   QString  s_workDir;
+
+  QColor    m_tabColor;
 };
 

--- kdebase/konsole/konsole/main.cpp  #1.288:1.289
@@ -509,4 +509,5 @@ extern "C" int KDE_EXPORT kdemain(int ar
         m->initMonitorSilence(sessionconfig->readBoolEntry("MonitorSilence0",false));
         m->initMasterMode(sessionconfig->readBoolEntry("MasterMode0",false));
+        m->initTabColor(sessionconfig->readColorEntry("TabColor"));
         counter++;
 
@@ -545,4 +546,6 @@ extern "C" int KDE_EXPORT kdemain(int ar
           key = QString("MasterMode%1").arg(counter);
           m->initMasterMode(sessionconfig->readBoolEntry(key,false));
+          key = QString("TabColor%1").arg(counter);
+          m->initTabColor(sessionconfig->readColorEntry(key));
           counter++;
         }
Comment 6 Richard Neill 2005-04-05 02:55:42 UTC
Thank you very much - I shall look forward to using this. 

One thought: the advantage of escape codes vs DCOP is that
a)they are compatible with the way that the rest of the prompts work
b)they work over a remote connection.

Eg: If I connect to a remote machine (called mocha) via ssh, I can have the remote .bashrc set the tab text:   mocha:~/
If I then become root on that machine, the tab text can be updated to 
  *mocha:~/    with a red * to denote root.

As I understand it, I don't think this can be done by DCOP.


Lastly, thanks very much again or your hard work - much appreciated!

Richard
Comment 7 Kurt Hindenburg 2005-05-16 00:35:16 UTC
SVN commit 414407 by hindenburg:


Add ESC code to change tab text color. Since t has to do with window
manipulation (according to xterm control seq), I decided to use it with
28.  This doesn't do anything according to the specs as far as I can tell.

change tab text color : \e[28;<color>t  color: 0-16,777,215

CCBUG: 80725



 M  +3 -0      trunk/KDE/kdebase/konsole/konsole/TEmuVt102.cpp  
 M  +1 -0      trunk/KDE/kdebase/konsole/konsole/TEmulation.h  
 M  +17 -0     trunk/KDE/kdebase/konsole/konsole/konsole.cpp  
 M  +1 -0      trunk/KDE/kdebase/konsole/konsole/konsole.h  


--- trunk/KDE/kdebase/konsole/konsole/TEmuVt102.cpp #414406:414407
@@ -511,6 +511,9 @@
 // resize = \e[8;<row>;<col>t
     case TY_CSI_PS('t',    8) : changeColLin( q /* col */, p /* lin */ ); break;
 
+// change tab text color : \e[28;<color>t  color: 0-16,777,215
+    case TY_CSI_PS('t',    28) : emit changeTabTextColor   ( p        ); break;
+
     case TY_CSI_PS('K',    0) : scr->clearToEndOfLine     (          ); break;
     case TY_CSI_PS('K',    1) : scr->clearToBeginOfLine   (          ); break;
     case TY_CSI_PS('K',    2) : scr->clearEntireLine      (          ); break;
--- trunk/KDE/kdebase/konsole/konsole/TEmulation.h #414406:414407
@@ -72,6 +72,7 @@
   void changeTitle(int arg, const char* str);
   void notifySessionState(int state);
   void zmodemDetected();
+  void changeTabTextColor(int color);
 
 public:
 
--- trunk/KDE/kdebase/konsole/konsole/konsole.cpp #414406:414407
@@ -1984,6 +1984,18 @@
 }
 
 // Called from emulation
+void Konsole::changeTabTextColor( int rgb )
+{
+    QColor color;
+    color.setRgb( rgb );
+    if ( !color.isValid() ) {
+        kdWarning()<<" Invalid RGB color "<<rgb<<endl;
+        return;
+    }
+    tabwidget->setTabColor( se->widget(), color );
+}
+
+// Called from emulation
 void Konsole::changeColLin(int columns, int lines)
 {
   if (b_allowResize && !b_fixedSize) {
@@ -2685,6 +2697,8 @@
            this, SLOT(slotGetSessionSchema(TESession*, QString &)));
   connect( s, SIGNAL(setSessionSchema(TESession*, const QString &)),
            this, SLOT(slotSetSessionSchema(TESession*, const QString &)));
+  connect( s->getEmulation(),SIGNAL(changeTabTextColor(int)), 
+           this,SLOT(changeTabTextColor(int)) );
 
   s->widget()->setVTFont(defaultFont);// Hack to set font again after newSession
   s->setSchemaNo(schmno);
@@ -3387,6 +3401,7 @@
   disconnect( _se->getEmulation(),SIGNAL(ImageSizeChanged(int,int)), this,SLOT(notifySize(int,int)));
   disconnect( _se->getEmulation(),SIGNAL(changeColLin(int, int)), this,SLOT(changeColLin(int,int)) );
   disconnect( _se->getEmulation(),SIGNAL(changeColumns(int)), this,SLOT(changeColumns(int)) );
+  disconnect( _se->getEmulation(),SIGNAL(changeTabTextColor(int)), this,SLOT(changeTabTextColor(int)) );
 
   disconnect( _se,SIGNAL(updateTitle()), this,SLOT(updateTitle()) );
   disconnect( _se,SIGNAL(notifySessionState(TESession*,int)), this,SLOT(notifySessionState(TESession*,int)) );
@@ -3486,6 +3501,8 @@
   connect( session->getEmulation(),SIGNAL(changeColumns(int)), this,SLOT(changeColumns(int)) );
   connect( session->getEmulation(),SIGNAL(changeColLin(int, int)), this,SLOT(changeColLin(int,int)) );
 
+  connect( session->getEmulation(),SIGNAL(changeTabTextColor(int)), this,SLOT(changeTabTextColor(int)) );
+
   activateSession(session);
 }
 
--- trunk/KDE/kdebase/konsole/konsole/konsole.h #414406:414407
@@ -156,6 +156,7 @@
   void updateKeytabMenu();
   void updateRMBMenu();
 
+  void changeTabTextColor(int);
   void changeColumns(int);
   void changeColLin(int columns, int lines);
   void notifySessionState(TESession* session,int state);
Comment 8 Kurt Hindenburg 2005-05-16 01:39:09 UTC
The only problem I see is that the uses will have to calculate what # to use.  I found kcalc works good for HEX->Decimal conversions.

My root PS1:
\[\033[0;32m\](\[\033[0;31m\]\u\[\033[0;32m\]@\[\033[0;33m\]\h\[\033[0;32m\])-(\[\033[0;36m\]$(date +%H:%M)\[\033[0;32m\])-(\[\033[0;36m\]\w\[\033[0;32m\])\[\033[0;36m\]>\[\033[0;37m\] \[\033[28;16711680t\]

16711680 is FF0000 (RRGGBB) which is red.
Comment 9 Kurt Hindenburg 2005-05-16 06:15:45 UTC
SVN commit 414464 by hindenburg:

Previous code didn't take into account user changing sessions; also
detaching session will retain tab text color now.

CCBUG: 80725


 M  +11 -7     trunk/KDE/kdebase/konsole/konsole/konsole.cpp  
 M  +1 -1      trunk/KDE/kdebase/konsole/konsole/konsole.h  
 M  +8 -0      trunk/KDE/kdebase/konsole/konsole/session.cpp  
 M  +2 -0      trunk/KDE/kdebase/konsole/konsole/session.h  
Comment 10 Xtal 2019-02-16 05:51:56 UTC
Hi, I'm currently trying to find a way to differentiate Konsole's tab using ESC codes or something similar.  Basically I want the tab background color, or icon to be different for each of my servers.

I came across this old ticket, but I'm unsure if it was actually implemented, or the feature still exists?

I'm using Konsole 18.12.1

Is there any way to do this still?  If so, could somebody please show an example shell command that would send the ESC sequence to change the current tab's color or icon?

Thanks