|
| 1 | + |
| 2 | + |
| 3 | +<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --> |
| 4 | + |
| 5 | +The quick brown fox jumps over the lazy dog. Jackdaws love my big sphinx |
| 6 | +of quartz. Pack my box with five dozen liquor jugs. How vexingly quick |
| 7 | +daft zebras jump! The five boxing wizards jump quickly. Sphinx of black |
| 8 | +quartz, judge my vow. Two driven jocks help fax my big quiz. Bright |
| 9 | +vixens jump; dozy fowl quack. |
| 10 | + |
| 11 | +``` python |
| 12 | +msg = await read_msg() |
| 13 | +id_ = msg.id |
| 14 | +cts = msg.content |
| 15 | +``` |
| 16 | + |
| 17 | +<div class="prose" markdown="1"> |
| 18 | + |
| 19 | +------------------------------------------------------------------------ |
| 20 | + |
| 21 | +<a |
| 22 | +href="https://github.com/AnswerDotAI/dialoghelper/blob/main/dialoghelper/exhash.py#L12" |
| 23 | +target="_blank" style="float:right; font-size:smaller">source</a> |
| 24 | + |
| 25 | +### msg_lnhashview |
| 26 | + |
| 27 | +``` python |
| 28 | + |
| 29 | +async def msg_lnhashview( |
| 30 | + id:str, # id of message to view |
| 31 | + dname:str='', # Dialog containing message; defaults to current dialog |
| 32 | +): |
| 33 | + |
| 34 | +``` |
| 35 | + |
| 36 | +*Show lnhash-addressed lines of a message* |
| 37 | + |
| 38 | +</div> |
| 39 | + |
| 40 | +<div class="prose" markdown="1"> |
| 41 | + |
| 42 | +------------------------------------------------------------------------ |
| 43 | + |
| 44 | +<a |
| 45 | +href="https://github.com/AnswerDotAI/dialoghelper/blob/main/dialoghelper/exhash.py#L22" |
| 46 | +target="_blank" style="float:right; font-size:smaller">source</a> |
| 47 | + |
| 48 | +### msg_exhash |
| 49 | + |
| 50 | +``` python |
| 51 | + |
| 52 | +async def msg_exhash( |
| 53 | + id:str, # id of message to edit |
| 54 | + cmds:list, # List of exhash command strings to apply |
| 55 | + dname:str='', # Dialog containing message; defaults to current dialog |
| 56 | +): |
| 57 | + |
| 58 | +``` |
| 59 | + |
| 60 | +*Verified line-addressed editor. Apply commands to msg `id` contents, |
| 61 | +return lnhash diff.* **NB**: *all* exhash commands *must* start with an |
| 62 | +address. The *only* allowed addresses are a single lnhash, or a pair |
| 63 | +separated by `,`. (I.e no `%`, `.`, etc.) **NB**: hashes are checked |
| 64 | +before each command is run. So be sure to have commands go last-\>first |
| 65 | +order to avoid changing earlier lines. |
| 66 | + |
| 67 | +Commands are like `ex`, but use lnhash addresses instead of bare line |
| 68 | +numbers: `lineno|hash|cmd` where hash is a 4-char hex content hash. Use |
| 69 | +`msg_lnhashview(text)` to get addresses before first use. |
| 70 | + |
| 71 | +Addressing: Single: `12|a3f2|cmd` Range: `12|a3f2|,15|b1c3|cmd` Special: |
| 72 | +`0|0000|` targets before line 1 (only with a or i) |
| 73 | + |
| 74 | +Commands: s/pat/rep/\[flags\] Substitute (regex). Flags: g=all, |
| 75 | +i=case-insensitive d Delete line(s) a Append text after line i Insert |
| 76 | +text before line c Change/replace line(s) j Join with next line; with |
| 77 | +range, joins all m dest Move line(s) after dest address t dest Copy |
| 78 | +line(s) after dest address \>\[n\] Indent n levels (default 1, 4 spaces |
| 79 | +each) \<\[n\] Dedent n levels (default 1) sort Sort lines alphabetically |
| 80 | +p Print (include in output without changing) g/pat/cmd Global: run cmd |
| 81 | +on matching lines g!/pat/cmd Inverted global (also v/pat/cmd) |
| 82 | + |
| 83 | +`cmds` is a required list of command strings. For `a`/`i`/`c`, include |
| 84 | +the text block in the same command string after a newline. Unlike `ex`, |
| 85 | +do NOT add a trailing `.` line — the string boundary ends the block. A |
| 86 | +trailing `.` will be inserted literally (with a warning). |
| 87 | + |
| 88 | +</div> |
| 89 | + |
| 90 | +<div class="prose" markdown="1"> |
| 91 | + |
| 92 | +------------------------------------------------------------------------ |
| 93 | + |
| 94 | +<a |
| 95 | +href="https://github.com/AnswerDotAI/dialoghelper/blob/main/dialoghelper/exhash.py#L68" |
| 96 | +target="_blank" style="float:right; font-size:smaller">source</a> |
| 97 | + |
| 98 | +### file_lnhashview |
| 99 | + |
| 100 | +``` python |
| 101 | + |
| 102 | +def file_lnhashview( |
| 103 | + path:str |
| 104 | +): |
| 105 | + |
| 106 | +``` |
| 107 | + |
| 108 | +*Show lnhash-addressed lines of a file* |
| 109 | + |
| 110 | +</div> |
| 111 | + |
| 112 | +<div class="prose" markdown="1"> |
| 113 | + |
| 114 | +------------------------------------------------------------------------ |
| 115 | + |
| 116 | +<a |
| 117 | +href="https://github.com/AnswerDotAI/dialoghelper/blob/main/dialoghelper/exhash.py#L73" |
| 118 | +target="_blank" style="float:right; font-size:smaller">source</a> |
| 119 | + |
| 120 | +### file_exhash |
| 121 | + |
| 122 | +``` python |
| 123 | + |
| 124 | +def file_exhash( |
| 125 | + path:str, cmds:list |
| 126 | +): |
| 127 | + |
| 128 | +``` |
| 129 | + |
| 130 | +*Verified line-addressed editor for files. Apply commands to file at |
| 131 | +`path`, return lnhash diff.* See `doc(msg_exhash)` for details |
| 132 | + |
| 133 | +</div> |
| 134 | + |
| 135 | +``` python |
| 136 | +tp = Path('tmp.txt') |
| 137 | +tp.write_text(cts) |
| 138 | +``` |
| 139 | + |
| 140 | + 313 |
| 141 | + |
| 142 | +``` python |
| 143 | +file_lnhashview("tmp.txt") |
| 144 | +``` |
| 145 | + |
| 146 | + '1|da2a| The quick brown fox jumps over the lazy dog.\n2|32e4| Jackdaws love my big sphinx of quartz.\n3|04e4| Pack my box with five dozen liquor jugs.\n4|025f| How vexingly quick daft zebras jump!\n5|c720| The five boxing wizards jump quickly.\n6|0666| Sphinx of black quartz, judge my vow.\n7|d61c| Two driven jocks help fax my big quiz.\n8|bc1b| Bright vixens jump; dozy fowl quack.' |
| 147 | + |
| 148 | +``` python |
| 149 | +file_exhash("tmp.txt", cmds=['1|da2a|,3|04e4|>']) |
| 150 | +``` |
| 151 | + |
| 152 | + '--- tmp.txt\n+++ tmp.txt\n-1|da2a| The quick brown fox jumps over the lazy dog.\n-2|32e4| Jackdaws love my big sphinx of quartz.\n-3|04e4| Pack my box with five dozen liquor jugs.\n+1|dfab| The quick brown fox jumps over the lazy dog.\n+2|e110| Jackdaws love my big sphinx of quartz.\n+3|a4ce| Pack my box with five dozen liquor jugs.\n 4|025f| How vexingly quick daft zebras jump!\n' |
| 153 | + |
| 154 | +``` python |
| 155 | +print(tp.read_text()) |
| 156 | +``` |
| 157 | + |
| 158 | + The quick brown fox jumps over the lazy dog. |
| 159 | + Jackdaws love my big sphinx of quartz. |
| 160 | + Pack my box with five dozen liquor jugs. |
| 161 | + How vexingly quick daft zebras jump! |
| 162 | + The five boxing wizards jump quickly. |
| 163 | + Sphinx of black quartz, judge my vow. |
| 164 | + Two driven jocks help fax my big quiz. |
| 165 | + Bright vixens jump; dozy fowl quack. |
| 166 | + |
| 167 | +``` python |
| 168 | +tp.unlink() |
| 169 | +``` |
0 commit comments