From 326d316dcb44ca3307244c2a4aa8f2c37c3a43f2 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 30 Jan 2016 10:25:49 +0100 Subject: Initial --- .gitignore | 2 + volume.cpp | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 .gitignore create mode 100644 volume.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..917f4b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +volume diff --git a/volume.cpp b/volume.cpp new file mode 100644 index 0000000..21f625b --- /dev/null +++ b/volume.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +int printusage(int,const char *const *argv,const char *message=NULL){ + if(message)cout<=0))return 0; + vol+=inc; + if(vol<0)vol=0; + if(vol>100)vol=100; + return setvolume(vol); +} + +int interact(bool &m,int &vol){ + char c=cin.get(); + if(c=='q'||c=='Q'||c=='\n'||c=='\r')return 1; + if(c=='l')return incvol(vol,5); + if(c=='h')return incvol(vol,-5); + if(c=='m'){ + m=!m; + setmuted(m); + return 0; + } + if(c!=27){ + cout<<7<2)return printusage(argc,argv); + if(argc==2){ + if(argv[1][0]=='\0')return printusage(argc,argv,"Invalid volume format"); + char *endp; + const int vol=strtol(argv[1],&endp,10); + if(*endp!='\0')return printusage(argc,argv,"Invalid volume format"); + if(vol<0||vol>100)return printusage(argc,argv,"Volume argument not in range"); + return setvolume(vol); + } + if(!isatty(1))return printusage(argc,argv,"Won't display slider if stdout is not a terminal"); + initscreen(); + atexit(endscreen); + bool m=getmuted(); + int vol=getvolume(); + while(true){ + displayslider(m,vol); + if(interact(m,vol))break; + } + cout<