[Tex/LaTex] How to set the Top Margin for a custom Verbatim environment (fancyvrb)

fancyvrbspacingverbatim

From the fancyvrb documentation, it looks like I can set left and right margins (paragraph 4.1.13) only. How can I set the top margin for my environment?

More specifically, given that I have a frame and a top title in my environment, I would like some extra padding between the top frame and the first line of text.

\newcommand{\shellheader}{This is a Shell}
\DefineVerbatimEnvironment{shell}{Verbatim}
{label=\shellheader,frame=single}

Best Answer

I propose a horrible hack that should take into account all your needs:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}


\DefineVerbatimEnvironment{shell}{Verbatim}{
  commandchars=\%\{\},
  label=\shelltitle,
  frame=single,
  formatcom=\setcounter{prompt}{0}\start
}
\newcommand{\shelltitle}{This is a shell}

\makeatletter
\def\start{\let\FV@FV@ProcessLine\FV@ProcessLine
  \def\FV@ProcessLine{\noindent\vrule height3ex depth2ex 
                      \hbox to\hsize{\kern\FV@FrameSep This is the shell prompt\hfil}%
                      \kern-.8pt\vrule\par
                      \let\FV@ProcessLine\FV@FV@ProcessLine
                      \FV@ProcessLine}%
}
\makeatother

\newcounter{prompt}
\newcommand{\prompt}{\stepcounter{prompt}\theprompt>}

\begin{document}
\begin{shell}
%prompt echo foo{}
foo
%prompt echo bar
bar
\end{shell}
\end{document}

Act on 3ex and 2ex for modifying the spacing before and after the fixed "This is the shell prompt".

enter image description here