3

This is following up to an earlier question:
Drawing Realistic Linux Command Shell Windows with tcolorbox


I'd like to be able to create something like this:

enter image description here


For the most part I can, but I can't redefine the prompt and colours, etc. So basically I want to be able to define multiple every listing line values or to somehow redefine it arbitrarily at certain points. For example:

alice

every listing line={\textcolor{magenta}{\small\ttfamily\bfseries{alice@localhost{\textcolor{black}:}\textcolor{cyan!60}{\url{~}}{\textcolor{black}\$ }}}}}

bob

every listing line={\textcolor{cyan}{\small\ttfamily\bfseries{bob@remotehost{\textcolor{black}:}\textcolor{cyan!60}{\url{~}}{\textcolor{black}\$ }}}}}

mwe

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\documentclass[]{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{tcolorbox,url,xcolor}
\tcbuselibrary{skins,xparse,minted,listings}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\newlength{\USER}
\setbox0\hbox{\small\ttfamily\bfseries ....}
\setlength{\USER}{\the\dimexpr\wd0+1pt}
\newcommand{\stdout}{\\\hspace*{-\USER}}    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\newtcblisting{macos}{size=small,halign title=flush left,
title={\textcolor{red!62}{\huge\ttfamily\bfseries{$\bullet\,$}\textcolor{orange!52!yellow}{\huge\ttfamily\bfseries{$\bullet\,$}\textcolor{green!80!black}{\huge\ttfamily\bfseries{$\bullet\,$}}}}}, 
colback=white,colupper=black,colframe=gray!25,listing only,
listing options={style=tcblatex,language=sh,escapeinside=``},
every listing line={\textcolor{magenta}{\small\ttfamily\bfseries{alice@localhost{\textcolor{black}:}\textcolor{cyan!60}{\url{~}}{\textcolor{black}\# }}}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
\begin{macos}
ssh bob@remotehost`\stdout`bob@remotehost's`\ `password:`\stdout`Linux remotehost 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686`\stdout`You have mail.`\stdout`Last login: Wed Oct 16 01:12:35 2012 from localhost`\stdout``\stdout`bob@remotehost:~$ _
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
\end{macos}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
  • 1
    Thanks for the edit! – user194703 Nov 27 '19 at 4:25
6

You can simply change the prompt on the fly. This is done by three commands

  • \StartAlice, after which the prompt becomes alice@localhost:~$,
  • \StartBob, after which the prompt becomes bob@localhost:~$,
  • \StartConsole which leads to no prompt.

MWE:

\documentclass[]{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{tcolorbox,url,xcolor}
\tcbuselibrary{skins,xparse,minted,listings}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\newtcblisting{macos}{size=small,halign title=flush left,
title={\textcolor{red!62}{\huge\ttfamily\bfseries{$\bullet\,$}\textcolor{orange!52!yellow}{\huge\ttfamily\bfseries{$\bullet\,$}\textcolor{green!80!black}{\huge\ttfamily\bfseries{$\bullet\,$}}}}}, 
colback=white,colupper=black,colframe=gray!25,listing only,
listing options={style=tcblatex,language=sh,escapeinside=``},
every listing line={\myprompt}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
\newcommand\myaliceprompt{\textcolor{magenta}{\small\ttfamily\bfseries{alice@localhost{\textcolor{black}:}\textcolor{cyan!60}{\url{~}}{\textcolor{black}\$ }}}}
\newcommand\mybobprompt{\textcolor{cyan}{\small\ttfamily\bfseries{bob@remotehost{\textcolor{black}:}\textcolor{cyan!60}{\url{~}}{\textcolor{black}\$ }}}}
\newcommand\myconsoleprompt{}
\newcommand{\StartBob}{\gdef\myprompt{\mybobprompt}}
\newcommand{\StartAlice}{\gdef\myprompt{\myaliceprompt}}
\newcommand{\StartConsole}{\gdef\myprompt{\myconsoleprompt}}    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\StartAlice
\begin{macos}
ssh bob@remotehost`\StartConsole`
bob@remotehost's`\ `password:
Linux remotehost 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686
You have mail.
Last login: Wed Oct 16 01:12:35 2012 from localhost
`\StartBob`
whoami`\StartConsole`
bob
\end{macos}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%            
\end{document}

enter image description here A perhaps more structured way is to only define an \SU command to switch. Then e.g. \SU{alice@localhost} changes the prompt to alice@localhost:~$, and \StartConsole works as above.

\documentclass[]{article}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{tcolorbox,url,xcolor}
\tcbuselibrary{skins,xparse,minted,listings}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\newtcblisting{macos}{size=small,halign title=flush left,
title={\textcolor{red!62}{\huge\ttfamily\bfseries{$\bullet\,$}\textcolor{orange!52!yellow}{\huge\ttfamily\bfseries{$\bullet\,$}\textcolor{green!80!black}{\huge\ttfamily\bfseries{$\bullet\,$}}}}}, 
colback=white,colupper=black,colframe=gray!25,listing only,
listing options={style=tcblatex,language=sh,escapeinside=``},
every listing line={\myprompt}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
\newcommand{\SU}[1]{\gdef\myprompt{\textcolor{magenta}{\small\ttfamily\bfseries{#1{\textcolor{black}:}\textcolor{cyan!60}{\url{~}}{\textcolor{black}\$ }}}}}
\newcommand{\StartConsole}{\gdef\myprompt{}}    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\SU{alice@localhost}
\begin{macos}
ssh bob@remotehost`\StartConsole`
bob@remotehost's`\ `password:
Linux remotehost 2.6.32-5-686 #1 SMP Sun Sep 23 09:49:36 UTC 2012 i686
You have mail.
Last login: Wed Oct 16 01:12:35 2012 from localhost
`\SU{bob@remotehost}`
whoami`\StartConsole`
bob
\end{macos}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%            
\end{document}
| improve this answer | |
  • 3
    @voices The lower part of tex.stackexchange.com/q/517976/165801 allows you to change the color. – user194703 Nov 27 '19 at 6:30
  • very nice. so can we use both styles in the same document? the first might be the purple ubuntu screen, then the next part might switch to the mac style and so on. I'm doing a bit of a writeup. There's lots of switching back and forth between different consoles, different computers, different usernames, etc. It's very effective, it looks great and very easy to read with the different visual queues, but having a little trouble getting it all to mesh together. Do I have to redefine everything, or should it all flow together nicely? – voices Nov 27 '19 at 7:01
  • @voices Now I do not understand the question. Can't you just define different listings style like macos-1, macos-2, ... ubuntu-1 and so on, and then switch the styles by saying \begin{macos-1}... \end{macos-1}, \begin{macos-2}... \end{macos-2} and so on? – user194703 Nov 27 '19 at 14:20
  • up until this point i could do that with \newtcblisting{...}. – voices Nov 27 '19 at 19:33
  • 1
    @voices You can still introduce as many \newtcblisting{...}s as you wish. As long as you have every listing line={\myprompt} in them they will collaborate with these tricks. – user194703 Nov 27 '19 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.