tcbuselibrary: redefinindo "cada linha de listagem"

tcbuselibrary: redefinindo "cada linha de listagem"

Isso segue uma pergunta anterior:
Desenhando janelas realistas de shell de comando do Linux com tcolorbox


Eu gostaria de poder criar algo assim:

insira a descrição da imagem aqui


Na maioria das vezes eu posso, mas não consigo redefinir o prompt e as cores, etc. Então, basicamente, quero ser capaz de definir vários every listing linevalores ou de alguma forma redefini-los arbitrariamente em determinados pontos. Por exemplo:

Alice

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

prumo

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

eu

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    

Responder1

Você pode simplesmente alterar o prompt na hora. Isso é feito por três comandos

  • \StartAlice, após o qual o prompt se torna alice@localhost:~$,
  • \StartBob, após o qual o prompt se torna bob@localhost:~$,
  • \StartConsoleo que não leva a nenhum aviso.

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}

insira a descrição da imagem aqui Uma maneira talvez mais estruturada é definir apenas um \SUcomando para alternar. Então, por exemplo, \SU{alice@localhost}altera o prompt para alice@localhost:~$e \StartConsolefunciona como acima.

\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}

informação relacionada