3

I want to highlight a complete terminal flow, mostly for the Cisco CLI, but Bash would be nice, too. As for now, the result achieved with the package lstlisting looks as follows:

enter image description here

I achieved that with the following code:

\lstdefinestyle{default}{
    backgroundcolor=\color{background},
    basicstyle=\ttfamily\small,
    breakatwhitespace=true,
    breaklines=true,
    commentstyle=\color{comments},
    deletekeywords={},
    escapeinside={}{},
    extendedchars=true,
    frame=lines,
    keepspaces=true,
    keywordstyle=\color{keywords},
    morekeywords={},
    numbers=left,
    numberstyle=\color{numbers},
    rulecolor=\color{numbers},
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    stepnumber=1,
    stringstyle=\color{strings},
    tabsize=2,
    title=\filename{\lstname}
}

\lstset{
    style=default,
}

\lstdefinelanguage{cisco-terminal}{
    basicstyle=\ttfamily\footnotesize\color{keywords},
    morecomment=[l][\color{black}]{\#},
    morecomment=[l][\color{black}]{>},
    morecomment=[s][\color{strings}]{*}{'},
    morecomment=[s][\color{strings}]{`}{'},
    numbers=none
}

The problem I have, is that the output of certain commands (do sh run) can only be highlighted when I surround them with ` and '. If I do not, certain snippets may look like this: enter image description here

Does anybody have an idea how to achieve the upper result in a better way (without the ` and ')? Are there any packages for this use case out there?

The test code can be found here: https://pastebin.com/ZSFb6ymi

A fully compileable example with and without workaround can be found here: https://pastebin.com/qRGfgkPj

Thank you in advance!

  • Could you please make your example a full compilable document? Ideally, one that includes a sample snippet of how the wrongly formatted code looks like and one that has your workarounds applied, so that we can see the differences between both. Perhaps switching to the minted package is another option. There already seems to be a lexer for Cisco console output – siracusa Aug 29 '18 at 2:45
  • Hello @siracusa. Here is the fully compileable document: pastebin.com/qRGfgkPj . Thank you for mentioning the minted package! I'll have a look at that, but I prefer lstlisting. – sebastian Sep 10 '18 at 13:31
  • I don't think you can get the desired result by just using listings' standard facilities. Perhaps a regex-based solution like in this question would work, but I'm not sure how to apply that here – siracusa Sep 14 '18 at 17:33

Your Answer

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

Browse other questions tagged or ask your own question.