Q:

Insert a block of code as a paragraph

Looking to display several lines of code in my report as one block, the same way that code is displayed on Stack Exchange. For inline code I've been using \tikzhl and \texttt:
\usepackage{tikz}
\newcommand*{\tikzhl}[1]{\tikz[baseline=(X.base)]
 \node[fill=black!10] (X) {#1};}

This seems a good solution for code integrated in paragraphs: 
But for several lines as their own paragraph it is not ideal:

What I would like to do is have it appear as the following with one bounding grey box:
Found 20 valid images for calibration
DIM=(1920, 1080)
K=np.array([[1374.9140598345757, 0.0, 996.2559942548266], [0.0, 1376.7481511557473, 541.0310811091442], [0.0, 0.0, 1.0]])
D=np.array([[-0.017077674858759682], [-0.30267173652198426], [1.7521950786149205], [-3.054359786737165]])

Adding a new line where it is wider than the page margins if possible, although I can do this manually if not possible.
Thanks in advance. Using Texmaker with MiKTeX 2.9.

A:

I keep your \tikzhl command, but it won't work with something like \tikzhl{\documentclass} (which is supposed to output \documentclass).
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
    basicstyle=\ttfamily,
    backgroundcolor=\color{black!10},
    breaklines=true
}
\usepackage{tikz}
\newcommand*{\tikzhl}[1]{\tikz[baseline=(X.base)]
 \node[fill=black!10,font=\ttfamily,inner sep=1pt] (X) {#1};}
\begin{document}
\begin{lstlisting}
Found 20 valid images for calibration
DIM=(1920, 1080)
K=np.array([[1374.9140598345757, 0.0, 996.2559942548266], [0.0, 1376.7481511557473, 541.0310811091442], [0.0, 0.0, 1.0]])
D=np.array([[-0.017077674858759682], [-0.30267173652198426], [1.7521950786149205], [-3.054359786737165]])
\end{lstlisting}

Package \tikzhl{listings} can do it for you.
\end{document}

