()
| 675 | } |
| 676 | |
| 677 | function completion() { |
| 678 | var tab, res, s, i, j, len, t, max_width, col, n_cols, row, n_rows; |
| 679 | res = get_completions(cmd, cursor_pos); |
| 680 | tab = res.tab; |
| 681 | if (tab.length === 0) |
| 682 | return; |
| 683 | s = tab[0]; |
| 684 | len = s.length; |
| 685 | /* add the chars which are identical in all the completions */ |
| 686 | for(i = 1; i < tab.length; i++) { |
| 687 | t = tab[i]; |
| 688 | for(j = 0; j < len; j++) { |
| 689 | if (t[j] !== s[j]) { |
| 690 | len = j; |
| 691 | break; |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | for(i = res.pos; i < len; i++) { |
| 696 | insert(s[i]); |
| 697 | } |
| 698 | if (last_fun === completion && tab.length == 1) { |
| 699 | /* append parentheses to function names */ |
| 700 | var m = res.ctx[tab[0]]; |
| 701 | if (typeof m == "function") { |
| 702 | insert('('); |
| 703 | if (m.length == 0) |
| 704 | insert(')'); |
| 705 | } else if (typeof m == "object") { |
| 706 | insert('.'); |
| 707 | } |
| 708 | } |
| 709 | /* show the possible completions */ |
| 710 | if (last_fun === completion && tab.length >= 2) { |
| 711 | max_width = 0; |
| 712 | for(i = 0; i < tab.length; i++) |
| 713 | max_width = Math.max(max_width, tab[i].length); |
| 714 | max_width += 2; |
| 715 | n_cols = Math.max(1, Math.floor((term_width + 1) / max_width)); |
| 716 | n_rows = Math.ceil(tab.length / n_cols); |
| 717 | std.puts("\n"); |
| 718 | /* display the sorted list column-wise */ |
| 719 | for (row = 0; row < n_rows; row++) { |
| 720 | for (col = 0; col < n_cols; col++) { |
| 721 | i = col * n_rows + row; |
| 722 | if (i >= tab.length) |
| 723 | break; |
| 724 | s = tab[i]; |
| 725 | if (col != n_cols - 1) |
| 726 | s = s.padEnd(max_width); |
| 727 | std.puts(s); |
| 728 | } |
| 729 | std.puts("\n"); |
| 730 | } |
| 731 | /* show a new prompt */ |
| 732 | readline_print_prompt(); |
| 733 | } |
| 734 | } |
nothing calls this directly
no test coverage detected