MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / completeLine

Function completeLine

tools/shell/linenoise.cpp:1250–1335  ·  view source on GitHub ↗

This is an helper function for linenoiseEdit() and is called when the * user types the key in order to complete the string currently in the * input. * * The state of the editing is encapsulated into the pointed linenoiseState * structure as described in the structure definition. */

Source from the content-addressed store, hash-verified

1248 * The state of the editing is encapsulated into the pointed linenoiseState
1249 * structure as described in the structure definition. */
1250static int completeLine(EscapeSequence& current_sequence, struct linenoiseState* l) {
1251 int nread, nwritten;
1252 char c = 0;
1253
1254 auto completion_list = linenoiseTabComplete(l);
1255 auto& completions = completion_list.completions;
1256 if (completions.empty()) {
1257 linenoiseBeep();
1258 } else {
1259 bool stop = false;
1260 bool accept_completion = false;
1261 uint64_t i = 0;
1262
1263 while (!stop) {
1264 /* Show completion or original buffer */
1265 if (i < completions.size()) {
1266 struct linenoiseState saved = *l;
1267
1268 l->len = completions[i].completion.size();
1269 l->pos = completions[i].cursor_pos;
1270 l->buf = (char*)completions[i].completion.c_str();
1271 refreshLine(l);
1272 l->len = saved.len;
1273 l->pos = saved.pos;
1274 l->buf = saved.buf;
1275 } else {
1276 refreshLine(l);
1277 }
1278
1279 nread = read(l->ifd, &c, 1);
1280 if (nread <= 0) {
1281 return -1;
1282 }
1283
1284 lndebug("\nComplete Character %d\n", (int)c);
1285 switch (c) {
1286 case TAB: /* tab */
1287 i = (i + 1) % (completions.size() + 1);
1288 if (i == completions.size()) {
1289 linenoiseBeep();
1290 }
1291 break;
1292 case ESC: { /* escape */
1293 auto escape = linenoiseReadEscapeSequence(l->ifd);
1294 switch (escape) {
1295 case EscapeSequence::SHIFT_TAB:
1296 // shift-tab: move backwards
1297 if (i == 0) {
1298 linenoiseBeep();
1299 } else {
1300 i--;
1301 }
1302 break;
1303 case EscapeSequence::ESCAPE:
1304 /* Re-show original buffer */
1305 if (i < completions.size()) {
1306 refreshLine(l);
1307 }

Callers 1

linenoiseEditFunction · 0.85

Calls 7

linenoiseTabCompleteFunction · 0.85
linenoiseBeepFunction · 0.85
refreshLineFunction · 0.85
readFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected