1 module dinu.command.command; 2 3 4 import dinu; 5 6 7 __gshared: 8 9 10 enum Type { 11 12 none, 13 script, 14 desktop, 15 history, 16 file, 17 directory, 18 output, 19 special, 20 bashCompletion, 21 processInfo, 22 window 23 24 } 25 26 27 shared immutable class Command { 28 29 string name; 30 Type type; 31 float[3] color; 32 float[3] colorInput; 33 string parameter; 34 35 protected this(Type type, string name, string parameter = ""){ 36 this.type = type; 37 this.name = name; 38 this.parameter = parameter; 39 color = options.colorFile; 40 colorInput = options.colorInput; 41 } 42 43 protected this(Type type, string name, float[3] color, string parameter = ""){ 44 this(type, name, parameter); 45 this.color = color; 46 } 47 48 string serialize(){ 49 return name; 50 } 51 52 string text(){ 53 return name; 54 } 55 56 string prepFilter(string filter){ 57 return filter; 58 } 59 60 string filterText(){ 61 return name; 62 } 63 64 string hint(){ 65 return ""; 66 } 67 68 size_t score(){ 69 return 0; 70 } 71 72 void run(){ run(parameter); } 73 abstract void run(string); 74 75 int draw(DrawEmpty draw, int[2] pos, bool selected, immutable(int)[] positions){ 76 int origX = pos.x; 77 78 foreach(p; positions){ 79 if(p < text.length){ 80 auto s = draw.width(text[0..p]); 81 draw.setColor([0.333, 0.333, 0.333]); 82 draw.rect([pos.x+s, pos.y-3], [draw.width(text[0..p+1])-s, 1.em]); 83 } 84 } 85 86 draw.setColor(color); 87 pos.x += draw.text(pos, text, 0); 88 draw.setColor(colorInput); 89 if(parameter.length) 90 pos.x += draw.text(pos, ' ' ~ parameter, 0); 91 return pos.x-origX; 92 } 93 94 void spawnCommand(string command, string arguments=""){ 95 options.configPath.execute( 96 type.to!string, 97 serialize.replace("!", "\\!"), 98 command, 99 arguments.replace("!", "\\!") 100 ); 101 } 102 103 } 104