1 module dinu.command.history; 2 3 4 import dinu; 5 6 7 shared immutable class CommandHistory: Command { 8 9 Type originalType; 10 Command command; 11 int pid; 12 13 this(int pid, Type originalType, string serialized, string parameter){ 14 this.originalType = originalType; 15 this.pid = pid; 16 if(originalType == Type.script) 17 command = new immutable CommandExec(serialized); 18 else if(originalType == Type.desktop) 19 command = new immutable CommandDesktop(serialized); 20 else if(originalType == Type.file) 21 command = new immutable CommandFile(serialized); 22 else if(originalType == Type.directory) 23 command = new immutable CommandDir(serialized); 24 else if(originalType == Type.special) 25 command = new immutable CommandSpecial(serialized); 26 else 27 command = new immutable CommandExec(serialized); 28 super(Type.history, command.text, parameter); 29 } 30 31 override string filterText(){ 32 return command.filterText() ~ parameter; 33 } 34 35 override string hint(){ 36 auto result = running[pid].result; 37 return result == long.max ? "~" : result.to!string; //command.hint; 38 } 39 40 override size_t score(){ 41 return commandBuilder.text.length 42 ? (parameter.length == 0 ? 0 : command.score) 43 : command.score*10; 44 //return commandBuilder.text.length ? command.score : 20 + running[pid].occurrences; 45 } 46 47 override int draw(DrawEmpty draw, int[2] pos, bool selected, immutable(int)[] positions){ 48 auto origX = pos.x; 49 /+ 50 if(auto r = (pid in running)){ 51 if(r.result != long.max){ 52 if(r.result) 53 draw.setColor(options.colorError); 54 draw.rect([pos.x-0.4.em, pos.y-3], [0.1.em, 1.em]); 55 }else 56 draw.setColor(options.colorHint); 57 draw.rect([pos.x-0.4.em, pos.y-3], [0.1.em, 1.em]); 58 } 59 +/ 60 pos.x += command.draw(draw, pos, selected, positions); 61 if(parameter.length) 62 draw.setColor(options.colorOutput); 63 pos.x += draw.text(pos, parameter); 64 return pos.x-origX; 65 } 66 67 override void run(string parameter){ 68 command.run(parameter); 69 } 70 71 } 72