% !TeX TXS-program:compile = txs:///pdflatex

\documentclass[11pt,a4paper]{ltxdoc}
\usepackage{sim-os-menus}
\usepackage{graphicx}
\usepackage{fancyvrb}
\usepackage{fancyhdr}
\usepackage{hyperref}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
%\rhead{\sffamily\small\affloetalab[Legende]}
\lfoot{\sffamily\small [sim-os-menus]}
\rfoot{\sffamily\small - \thepage{} -}
%\rfoot{\hyperlink{matoc}{\small\faArrowAltCircleUp[regular]}}
\usepackage{hologo}
\providecommand\tikzlogo{Ti\textit{k}Z}
\providecommand\TeXLive{\TeX{}Live\xspace}
\providecommand\PSTricks{\textsf{PSTricks}\xspace}
\let\pstricks\PSTricks
\let\TikZ\tikzlogo

\urlstyle{same}
\hypersetup{pdfborder=0 0 0}
\usepackage[margin=2cm]{geometry}
\setlength{\parindent}{0pt}
\def\TPversion{0.1.2}
\def\TPdate{18/09/2024}
\usepackage{soul}
\sethlcolor{lightgray!25}
\NewDocumentCommand\MontreCode{ m }{%
	\hl{\vphantom{\texttt{pf}}\texttt{#1}}%
}

\begin{document}

\pagestyle{fancy}

\thispagestyle{empty}

\begin{center}
	\begin{minipage}{0.88\linewidth}
	\begin{tcolorbox}[colframe=yellow,colback=yellow!15]
		\begin{center}
			\begin{tabular}{c}
				{\Huge \texttt{sim-os-menus}}\\
				\\
				{\LARGE Simulate 'windows', 'terminal' or} \\
				{\LARGE 'context menu' like in an OS.} \\
				\\
				{\small \texttt{Version \TPversion{} -- \TPdate}}
		\end{tabular}
		\end{center}
	\end{tcolorbox}
\end{minipage}
\end{center}

\begin{center}
	\begin{tabular}{c}
	\texttt{Cédric Pierquet}\\
	{\ttfamily c pierquet -- at -- outlook . fr}\\
	\texttt{\url{https://github.com/cpierquet/sim-os-menus}} \\
\end{tabular}
\end{center}

\hrule

\vfill

\begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
\ContextMenu[Font=\sffamily,ListSeps={1,3/1/4/1/},ListOffsets={1,2,1,0}]{%
	Menu1(>),Menu2,Menu3(>)(*),Menu4 §
	SubMenuA(>),SubMenuB(>)(*) §
	SubSubMenu1,SubSubMenu2,SubSubMenu3(>)(*),SubSubMenu4,SubSubMenu5(>) §
	SSSSMa,SSSSMa(>)(*),SSSSMc §
	OK(*),KO
}
\end{tcolorbox}

\begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
\begin{TermUnix}[Width=12cm,Align=center]{}
test@DESKTOP:~$ ping -c 2 ctan.org
PING ctan.org (5.35.249.60) 56(84) bytes of data.
\end{TermUnix}
\end{tcolorbox}

\begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
\begin{IMGViewer}[Width=12cm]{}
\includegraphics[width=5cm]{example-image-b}
\end{IMGViewer}
\end{tcolorbox}

\begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
\begin{TermMac}[Width=14cm,Align=flush left]{}
[test@server]$ ping -c 2 ctan.org
PING ctan.org (5.35.249.60) 56(84) bytes of data.
\end{TermMac}
\end{tcolorbox}

\vfill~

\pagebreak

\phantomsection

\hypertarget{matoc}{}

\tableofcontents

\vspace*{5mm}

\hrule

\vspace*{5mm}

\section{Introduction}

\subsection{Description}

With this package you can create context menu, or terminal, or doc viewer, like in an OS.

Global styles are mostly fixed, but some customizations are possible.

\subsection{Loading}

To load the package, simply use :

\begin{quote}
\begin{verbatim}
\usepackage{sim-os-menus}
\end{verbatim}
\end{quote}

The package loads the packages :

\begin{itemize}
	\item \MontreCode{tikz} (with \MontreCode{calc,positioning}), \MontreCode{pgf}, \MontreCode{pgffor} ;
	\item \MontreCode{calc}, \MontreCode{fontawesome5} ;
	\item \MontreCode{simplekv}, \MontreCode{xintexpr}, \MontreCode{listofitems}, \MontreCode{xstring} ;
	\item \MontreCode{settobox}, \MontreCode{tabularray} ;
	\item \MontreCode{tcolorbox} (with \MontreCode{breakable,fitting,skins,listings,listingsutf8,hooks}).
\end{itemize}

\vfill

\subsection{History}

\begin{quote}
\begin{verbatim}
0.1.2 : Script editor viewer 'like'
0.1.1 : French version of the commands
0.1.0 : Initial version
\end{verbatim}
\end{quote}

\pagebreak

\section{The macros}

\subsection{Context menu}

I order to create a context menu, the command is :

\begin{quote}
\begin{verbatim}
%----contextual menu
\ContextMenu[keys]{list of items}<tikz options>
\end{verbatim}
\end{quote}

Optional keys, between \MontreCode{[...]} are :

\begin{itemize}
	\item \MontreCode{ColBack} := background color ;
	\item \MontreCode{ColHL} : = highlight color ;
	\item \MontreCode{Rounded} := boolean for rounded corners (\MontreCode{true} by default) ;
	\item \MontreCode{Font} := font for the items (\MontreCode{\textbackslash normalsize\textbackslash normalfont} by default) ;
	\item \MontreCode{ColItems} := color(s) for the items (\MontreCode{black} by default) ;
	\item \MontreCode{MarginV} := vertical margin of the lines (\MontreCode{6pt} by default) ;
	\item \MontreCode{MarginH} := horizontal margin of the lines (\MontreCode{12pt} by default) ;
	\item \MontreCode{Arrow} := character for the arrow (\MontreCode{\textbackslash faCaretRight} by default) ;
	\item \MontreCode{ListSeps} := list for the possible sep lines (empty or for all the levels !) ;
	\item \MontreCode{ListIcons} := list for the possible icons (empty or for all the levels/items !) ;
	\item \MontreCode{ListOffsets} := list for the possible vertical offset of levels (from 2, \ldots !) (empty or for all the sub-levels !) ;
	\item \MontreCode{Icons} := boolean for icons (\MontreCode{false} by default) ;
	\item \MontreCode{Bar} := boolean for small vertical bar with icons (\MontreCode{true} by default) ;
	\item \MontreCode{Space} := horizontal space between levels (\MontreCode{-0.125} by default).
\end{itemize}

\medskip

The mandatory argument, between \MontreCode{\{...\}}, is given as :

\smallskip

\hfill\MontreCode{item1A,item1B,... § item2A,itemp2B,... § ...}\hfill~

\begin{itemize}
	\item if an item ends with \MontreCode{(*)}, this is the beginning of the next level (\underline{only one} by level !) ;
	\item if an item ends with \MontreCode{(>)} (\underline{before} optional \MontreCode{(*)}), an arrow is written at the end of the line.
\end{itemize}

A correct usage of the syntax is necessary for the code !

\vspace{5mm}

A few tips, due to \MontreCode{ListIcons}, \MontreCode{ListOffsets} and \MontreCode{ListSeps} keys, which are \textit{sensitive} :

\begin{itemize}
	\item \MontreCode{ListIcons} must have the same number of elements than the number of levels/items (with possible empty items) ;
	\item \MontreCode{ListSeps} must have the same number of elements than the number of levels (with possible empty items) ;
	\item \MontreCode{ListOffsets} must have the same number of elements than the numbers of sub-levels (with 0 si no offset !).
\end{itemize}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
%default style
\ContextMenu{Item1A(>),Item1B,Item1C(>)(*),Item1D § Item2A(*),Item2B(>),Item2C}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
%custom style
\ContextMenu[Rounded=false,ColBack=yellow,ColHL=teal,%
  ListSeps={1,3/2},ColItems={black/white},Icons,Space=0,%
  ListIcons={\faCut,\faIcon[regular]{copy},\faCopy,\faPaste / \faNotEqual}]
  {Item1A(>)(*),Item1B,Item1C(>),Item1D § Item2A(*),Item2B(>),Item2C}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\ContextMenu[Font=\sffamily,ListSeps={1,3/1/4/1/},ListOffsets={1,2,1,0}]{%
  Menu1(>),Menu2,Menu3(>)(*),Menu4 §
  SubMenuA(>),SubMenuB(>)(*) §
  SubSubMenu1,SubSubMenu2,SubSubMenu3(>)(*),SubSubMenu4,SubSubMenu5(>) §
  SSSSMa,SSSSMa(>)(*),SSSSMc §
  OK(*),KO
}
\end{tcblisting}

\pagebreak

\subsection{Terminal}

In order to create a terminal (Win/UNiX/Mac), environments are :

\begin{quote}
\begin{verbatim}
%----Windows like terminal
\begin{TermWin}[keys]{tcbox options}
    ...
\end{TermWin}

%----UNiX like terminal
\begin{TermUnix}[keys]{tcbox options}
    ...
\end{TermUnix}

%----OSX like terminal
\begin{TermMac}[keys]{tcbox options}
    ...
\end{TermMac}
\end{verbatim}
\end{quote}

Optional keys, between \MontreCode{[...]} are :

\begin{itemize}
	\item \MontreCode{Title} := title of the terminal (\MontreCode{Terminal Win/UNiX/Mac} by default) ;
	\item \MontreCode{Align} := horizontal alignment of the box (\MontreCode{center} by default) ;
	\item \MontreCode{Width} := width of the box (\MontreCode{\textbackslash linewidth} by default).
\end{itemize}

\medskip

The mandatory argument, between \MontreCode{\{...\}}, are options to give to the tcbox.

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\begin{TermWin}{}
Microsoft Windows [version 10.0.22000.493]
(c) Microsoft Corporation. Tous droits réservés.
C:\Users\test>ping ctan.org
Envoi d'une requête 'ping' sur ctan.org [5.35.249.60] avec 32 octets de données :
Réponse de 5.35.249.60 : octets=32 temps=35 ms TTL=51
Réponse de 5.35.249.60 : octets=32 temps=37 ms TTL=51
Réponse de 5.35.249.60 : octets=32 temps=35 ms TTL=51
Réponse de 5.35.249.60 : octets=32 temps=39 ms TTL=51
Statistiques Ping pour 5.35.249.60:
Paquets : envoyés = 4, reçus = 4, perdus = 0 (perte 0%),
Durée approximative des boucles en millisecondes :
Minimum = 35ms, Maximum = 39ms, Moyenne = 36ms
\end{TermWin}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\begin{TermUnix}[Align=flush right]{hbox}
test@DESKTOP:~$ ping -c 2 ctan.org
PING ctan.org (5.35.249.60) 56(84) bytes of data.
\end{TermUnix}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\begin{TermMac}[Width=14cm,Align=flush left]{}
[test@server]$ ping -c 2 ctan.org
PING ctan.org (5.35.249.60) 56(84) bytes of data.
\end{TermMac}
\end{tcblisting}

\pagebreak

\subsection{Viewers}

In order to create a 'fake' viewer (for \textsf{pdf} or \textsf{img}), environments are :

\begin{quote}
\begin{verbatim}
%----PDF Viewer like
\begin{PDFViewer}[keys]{tcbox options}
    ....
\end{PDFViewer}

%----Image Viewer like
\begin{IMGViewer}[keys]{tcbox options}
    ....
\end{IMGViewer}

%----Script editor like
\begin{PYViewer}[keys]{tcbox options}
    ....
\end{PYViewer}
\end{verbatim}
\end{quote}

Optional keys, between \MontreCode{[...]} are :

\begin{itemize}
	\item \MontreCode{Title} := title of the viewer ;
	\item \MontreCode{Align} := horizontal alignment of the box (\MontreCode{center} by default) ;
	\item \MontreCode{Width} := width of the box (\MontreCode{\textbackslash linewidth} by default) ;
	\item \MontreCode{Halign} := horizontal alignment fot the content (\MontreCode{left} by default) ;
	\item \MontreCode{Icons} := boolean for the icons (\MontreCode{true} by default).
\end{itemize}

\medskip

The mandatory argument, between \MontreCode{\{...\}}, are options to give to the tcbox.

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\begin{PDFViewer}{hbox}
\fbox{\includegraphics[page=35,width=6cm]{ProfLycee-doc.pdf}}%
\fbox{\includegraphics[page=36,width=6cm]{ProfLycee-doc.pdf}}
\end{PDFViewer}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\begin{PDFViewer}[Width=14cm,Icons=false]{}
\fbox{\includegraphics[page=65,width=4.75cm]{ProfLycee-doc.pdf}}
\end{PDFViewer}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\begin{IMGViewer}[Icons=false]{hbox}
\includegraphics[width=5cm]{example-image-b}
\end{IMGViewer}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
\begin{IMGViewer}[Width=12cm]{}
\includegraphics[width=3cm]{example-image}
\end{IMGViewer}
\end{tcblisting}

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5}
%with listings, or piton, for example
\begin{PYViewer}[width=12cm]{}
\begin{lstlisting}%
    [
        language=python,basicstyle=\ttfamily\small,
        keywordstyle=\color{green!50!black},tabsize=4,
        keywordstyle={[2]\color{magenta}},
        numbers=left,numbersep=3mm,xleftmargin=5mm,
        aboveskip=0pt,belowskip=0pt,
        numberstyle=\footnotesize\ttfamily\color{gray}
    ]
nterms = int(input("Entrez un nombre: "))

n1 = 0
n2 = 1

print("\n la suite Fibonacci est : ")
print(n1, ",", n2, end=", ")

for i in range(2, nterms):
    suivant = n1 + n2
    print(suivant, end=", ")

n1 = n2
n2 = suivant
\end{lstlisting}
\end{PYViewer}
\end{tcblisting}


\end{document}