# listings-package custom language delimiter match left-side

I'm trying to define a new language cli-like interface, but I can not figure out how the use the delimiter to match my prompt.

I want to apply tree different styles to the text. In the example below I have underlined each char with a ~, - or = to signal what style group they should belong to.

# configure terminal
~ ==================
--------~ ========================
(something-something)# url http://10.99.10.1:8000/path
---------------------~ ===============================


I have been experimenting with this:

\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{iCli}
{
comment=[l]{\%},
basicstyle=\small,
keywords={\#},
keywordstyle=\textbf,
delim=[s][keywordstyle]{(}{\#}
}

\begin{document}
\begin{lstlisting}[language=iCli]
% This is a comment
# configure terminal
\end{lstlisting}
\end{document}


But it does not highlight # as a keyword

• Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Sep 26, 2014 at 11:10
• So, to be clear, you want to highlight (config) and (something-something) in red, but not the following # or the first #. Correct? What color should # characters be highlighted in? Sep 26, 2014 at 11:13
• I would like the text before the # to be red(or some other color), and then I would like all # to be bold, and the other text normal. Sep 26, 2014 at 12:10
• @Jubobs I added a compilable example Sep 26, 2014 at 12:11
• It would also be okay if I could get the complete prompt (from the beginning of the line to #) in bold. Sep 26, 2014 at 12:13

A bit of hacking is required; see below.

\documentclass{article}

% the following two packages are for bold typewriter font
\usepackage[T1]{fontenc}
\usepackage{beramono}

\usepackage{listings}
\usepackage{xcolor}

\lstdefinelanguage{iCli}{
comment    = [l]{\%},
literate   = \#{{\processhash}}1,              %<-- required for bold prompt
moredelim  = **[is][\processmydelims]{(}{)\#}, %<-- for highlighting (...)#
basicstyle = \ttfamily,                        %<-- for a nice typewriter font
}

% helper macros
\newcommand\processmydelimsend{}
\newcommand\processmydelims{%
\renewcommand\processmydelimsend{\textcolor{red}{)}\textbf{\#}\egroup}%
\bgroup\color{red}(\aftergroup\processmydelimsend%
}
\makeatletter
\newcommand\processhash{%
\ifnum\lst@mode=\lst@Pmode%
\bfseries%
\fi
\#%
}
\makeatother

\begin{document}

\begin{lstlisting}[language=iCli]
# configure terminal