I am trying to define a tcblistings environment that should work under the following syntax...
\begin{code}{TITLE}{LANG}{CAPTION}{OPTS}
code here
\end{code}
Everything but the language should be optional. I want to add a listings caption starting from the top left and to reshape around the title box. The following code is the closest I got (inspired by this and this)...
\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings, breakable, skins}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[T1]{fontenc}
\usepackage[ttdefault=true]{AnonymousPro}
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\newtcblisting[auto counter]{code}[4][]{
enhanced,
attach boxed title to top right={yshift=-\tcboxedtitleheight},
boxed title style={
size=small,colback=gray!50,
colframe=gray!50,
sharp corners=downhill,
arc=.5cm,
top=1mm,bottom=1mm,left=1mm,right=1mm
},
fonttitle=\color{black}\itshape\ttfamily,
colframe=gray!20,
top=\tcboxedtitleheight,
bottom=\smallskipamount,
sharp corners=downhill,
arc=.5cm,
overlay={
\begin{tcbclipinterior}
\fill[gray!25](frame.south west)
rectangle ([xshift=5.1mm]frame.north west);
\end{tcbclipinterior}},
listing remove caption=false,
listing only,
listing options={
numbers=left,
numberstyle=\tiny,
captionpos=t,
language=#3,
xleftmargin=0.6em,
basicstyle=\fontfamily{AnonymousPro}\selectfont,
keywordstyle=\bfseries\color{pblue},
stringstyle=\bfseries\itshape\color{green!40!black},
commentstyle=\bfseries\itshape\color{black!60},
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
tabsize=1,
caption=#4,
% emph={
% downto, for, String, TextView, Toast, Button, EditText, ImageView, Typeface, Intent, WebView, WebSettings, SwipeRefreshLayout, RelativeLayout, Animation, AlertDialog, SharedPreferences, Editor, ToggleButton, CardView, LinearLayout, gradient, shape,
% },
emphstyle={\bfseries\color{pblue}},
},
title=#2,
#1
}
\begin{document}
\begin{code}{Hello Java}{Java}{My caption}
String s = "Hello World";
Animation from_top = AnimationUtils.loadAnimation(this, R.anim.from_top);
imageView.setAnimation(from_top);
// change activity with fade animation
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
finish();
}
}, SPLASH_TIMEOUT);
\end{code}
\end{document}
Which results in...
Is there any way to control the position and style of the lstlistings caption inside the tcolorbox to achieve the desired result? Alternatively, how can I define another caption apart from the listing's one to achieve the same result?
Additionally, is it possible to modify things so that I can specify the environment like...
\begin{code}[lang={LANG}, title={TITLE}, caption={CAPTION},...}
code here
\end{code}
?

