
Dies ist eine Fortsetzung einer früheren Frage:
Zeichnen realistischer Linux-Befehlsshell-Fenster mit tcolorbox
Ich möchte in der Lage sein, so etwas zu erstellen:
Das kann ich größtenteils, aber ich kann die Eingabeaufforderung und Farben usw. nicht neu definieren. Im Grunde möchte ich also mehrere every listing line
Werte definieren oder sie an bestimmten Stellen irgendwie beliebig neu definieren können. Beispiel:
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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Antwort1
Sie können die Eingabeaufforderung einfach im laufenden Betrieb ändern. Dies geschieht durch drei Befehle
\StartAlice
, danach wird die Eingabeaufforderung zualice@localhost:~$
,\StartBob
, danach wird die Eingabeaufforderung zubob@localhost:~$
,\StartConsole
was zu keiner Eingabeaufforderung führt.
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}
Ein vielleicht strukturierterer Weg besteht darin, nur einen
\SU
Befehl zum Umschalten zu definieren. Dann \SU{alice@localhost}
ändert sich beispielsweise die Eingabeaufforderung in alice@localhost:~$
und \StartConsole
funktioniert wie oben.
\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}