Quellcode durchsuchen

added cancellation parsing in format

naelstrof vor 7 Jahren
Ursprung
Commit
96de1eaa68
1 geänderte Dateien mit 7 neuen und 5 gelöschten Zeilen
  1. 7
    5
      src/main.cpp

+ 7
- 5
src/main.cpp Datei anzeigen

@@ -42,7 +42,7 @@ SlopOptions* getOptions( Options& options ) {
42 42
     return foo;
43 43
 }
44 44
 
45
-std::string formatOutput( std::string input, SlopSelection selection ) {
45
+std::string formatOutput( std::string input, SlopSelection selection, bool cancelled ) {
46 46
     std::stringstream output;
47 47
     for( unsigned int i=0;i<input.length();i++) {
48 48
         if ( input[i] == '%' ) {
@@ -56,6 +56,8 @@ std::string formatOutput( std::string input, SlopSelection selection ) {
56 56
                 case 'Y': output << round(selection.y); break;
57 57
                 case 'w':
58 58
                 case 'W': output << round(selection.w); break;
59
+                case 'c':
60
+                case 'C': output << cancelled; break;
59 61
                 case 'h':
60 62
                 case 'H': output << round(selection.h); break;
61 63
                 case 'g':
@@ -64,7 +66,7 @@ std::string formatOutput( std::string input, SlopSelection selection ) {
64 66
                 case 'i':
65 67
                 case 'I': output << selection.id; break;
66 68
                 case '%': output << "%"; break;
67
-                default: throw new std::invalid_argument( std::string()+"Expected x, y, w, h, g, i, or % after % in format. Got `" + input[i+1] + "`." );
69
+                default: throw new std::invalid_argument( std::string()+"Expected x, y, w, h, g, i, c, or % after % in format. Got `" + input[i+1] + "`." );
68 70
              }
69 71
             i++;
70 72
             continue;
@@ -163,7 +165,7 @@ int app( int argc, char** argv ) {
163 165
     std::string format;
164 166
     bool gotFormat = options.getString("format", 'f', format);
165 167
     if ( gotFormat ) {
166
-        formatOutput( format, selection );
168
+        formatOutput( format, selection, false );
167 169
     }
168 170
 
169 171
     // Finally we do the real selection.
@@ -179,10 +181,10 @@ int app( int argc, char** argv ) {
179 181
     }
180 182
     // If we recieved a format option, we output the specified output.
181 183
     if ( gotFormat ) {
182
-        std::cout << formatOutput( format, selection );
184
+        std::cout << formatOutput( format, selection, cancelled );
183 185
         return 0;
184 186
     }
185
-    std::cout << formatOutput( "%g\n", selection );
187
+    std::cout << formatOutput( "%g\n", selection, cancelled );
186 188
     return 0;
187 189
 }
188 190