Browse Source

added cancellation parsing in format

naelstrof 7 years ago
parent
commit
96de1eaa68
1 changed files with 7 additions and 5 deletions
  1. 7
    5
      src/main.cpp

+ 7
- 5
src/main.cpp View File

42
     return foo;
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
     std::stringstream output;
46
     std::stringstream output;
47
     for( unsigned int i=0;i<input.length();i++) {
47
     for( unsigned int i=0;i<input.length();i++) {
48
         if ( input[i] == '%' ) {
48
         if ( input[i] == '%' ) {
56
                 case 'Y': output << round(selection.y); break;
56
                 case 'Y': output << round(selection.y); break;
57
                 case 'w':
57
                 case 'w':
58
                 case 'W': output << round(selection.w); break;
58
                 case 'W': output << round(selection.w); break;
59
+                case 'c':
60
+                case 'C': output << cancelled; break;
59
                 case 'h':
61
                 case 'h':
60
                 case 'H': output << round(selection.h); break;
62
                 case 'H': output << round(selection.h); break;
61
                 case 'g':
63
                 case 'g':
64
                 case 'i':
66
                 case 'i':
65
                 case 'I': output << selection.id; break;
67
                 case 'I': output << selection.id; break;
66
                 case '%': output << "%"; break;
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
             i++;
71
             i++;
70
             continue;
72
             continue;
163
     std::string format;
165
     std::string format;
164
     bool gotFormat = options.getString("format", 'f', format);
166
     bool gotFormat = options.getString("format", 'f', format);
165
     if ( gotFormat ) {
167
     if ( gotFormat ) {
166
-        formatOutput( format, selection );
168
+        formatOutput( format, selection, false );
167
     }
169
     }
168
 
170
 
169
     // Finally we do the real selection.
171
     // Finally we do the real selection.
179
     }
181
     }
180
     // If we recieved a format option, we output the specified output.
182
     // If we recieved a format option, we output the specified output.
181
     if ( gotFormat ) {
183
     if ( gotFormat ) {
182
-        std::cout << formatOutput( format, selection );
184
+        std::cout << formatOutput( format, selection, cancelled );
183
         return 0;
185
         return 0;
184
     }
186
     }
185
-    std::cout << formatOutput( "%g\n", selection );
187
+    std::cout << formatOutput( "%g\n", selection, cancelled );
186
     return 0;
188
     return 0;
187
 }
189
 }
188
 
190