summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-01-30 13:55:30 +0100
committertomsmeding <tom.smeding@gmail.com>2016-01-30 13:55:30 +0100
commit27b424b261d9c012b8490f6365b0daf3fc669242 (patch)
treeb95590d5d532307533109894374e7dfdded66f40
parentfabeccb1a1b3f87793bbd70a6eee2165df53aa24 (diff)
output volume state when stdout!=tty
-rw-r--r--volume.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/volume.cpp b/volume.cpp
index 4ad5b03..ca2f564 100644
--- a/volume.cpp
+++ b/volume.cpp
@@ -9,11 +9,14 @@ using namespace std;
int printusage(int,const char *const *argv,const char *message=NULL){
if(message)cout<<message<<endl;
- cout<<"Usage: "<<argv[0]<<" [volume]"<<endl;
- cout<<"If [volume] is given, changes volume to that value. (Integer in [0,100].)"<<endl;
- cout<<"Otherwise, it shows a graphical slider, adjustable with the arrow keys or h/j/k/l."<<endl;
- cout<<"In graphical mode, 'm' toggles whether sound is muted."<<endl;
- cout<<"If the output is not a tty, the graphical slider is disabled."<<endl;
+ cout<<"Usage: "<<argv[0]<<" [volume]\n"
+ "If [volume] is given, changes volume to that value. (Integer in [0,100].)\n"
+ "Otherwise, it shows a graphical slider, adjustable with the arrow keys or h/j/k/l;\n"
+ "'m' toggles whether sound is muted; a number directly sets the volume.\n"
+ "Enter or 'q' exits graphical mode.\n"
+ "If the output is not a tty, the current volume is outputted, possibly suffixed\n"
+ "with an 'm' if muted."
+ <<endl;
return 1;
}
@@ -172,7 +175,10 @@ int main(int argc,char **argv){
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");
+ if(!isatty(1)){
+ cout<<getvolume()<<(getmuted()?"m":"")<<endl;
+ return 0;
+ }
initscreen();
atexit(endscreen);
bool m=getmuted();