Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
|
Jakob Kummerow
2011/09/14 14:18:42
2011
| |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 '\\', '\'', '`', '@', '.', '>', '<', '=', ';', '|', '&', '{', '(', | 65 '\\', '\'', '`', '@', '.', '>', '<', '=', ';', '|', '&', '{', '(', |
| 66 '\0'}; | 66 '\0'}; |
| 67 | 67 |
| 68 | 68 |
| 69 bool ReadLineEditor::Open() { | 69 bool ReadLineEditor::Open() { |
| 70 rl_initialize(); | 70 rl_initialize(); |
| 71 rl_attempted_completion_function = AttemptedCompletion; | 71 rl_attempted_completion_function = AttemptedCompletion; |
| 72 rl_completer_word_break_characters = kWordBreakCharacters; | 72 rl_completer_word_break_characters = kWordBreakCharacters; |
| 73 rl_bind_key('\t', rl_complete); | 73 rl_bind_key('\t', rl_complete); |
| 74 using_history(); | 74 using_history(); |
| 75 stifle_history(Shell::kMaxHistoryEntries); | |
| 75 return read_history(Shell::kHistoryFileName) == 0; | 76 return read_history(Shell::kHistoryFileName) == 0; |
| 76 } | 77 } |
| 77 | 78 |
| 78 | 79 |
| 79 bool ReadLineEditor::Close() { | 80 bool ReadLineEditor::Close() { |
| 80 return write_history(Shell::kHistoryFileName) == 0; | 81 return write_history(Shell::kHistoryFileName) == 0; |
| 81 } | 82 } |
| 82 | 83 |
| 83 | 84 |
| 84 i::SmartArrayPointer<char> ReadLineEditor::Prompt(const char* prompt) { | 85 i::SmartArrayPointer<char> ReadLineEditor::Prompt(const char* prompt) { |
| 85 char* result = readline(prompt); | 86 char* result = readline(prompt); |
| 86 return i::SmartArrayPointer<char>(result); | 87 return i::SmartArrayPointer<char>(result); |
| 87 } | 88 } |
| 88 | 89 |
| 89 | 90 |
| 90 void ReadLineEditor::AddHistory(const char* str) { | 91 void ReadLineEditor::AddHistory(const char* str) { |
| 92 // Do not record empty input. | |
| 93 if (strlen(str) == 0) return; | |
| 94 // Remove duplicate history entry. | |
| 95 history_set_pos(0); | |
| 96 if (current_history()) { | |
| 97 do { | |
| 98 if (strcmp(current_history()->line, str) == 0) { | |
| 99 remove_history(where_history()); | |
| 100 break; | |
| 101 } | |
| 102 } while (next_history()); | |
| 103 } | |
| 91 add_history(str); | 104 add_history(str); |
| 92 } | 105 } |
| 93 | 106 |
| 94 | 107 |
| 95 char** ReadLineEditor::AttemptedCompletion(const char* text, | 108 char** ReadLineEditor::AttemptedCompletion(const char* text, |
| 96 int start, | 109 int start, |
| 97 int end) { | 110 int end) { |
| 98 char** result = completion_matches(text, CompletionGenerator); | 111 char** result = completion_matches(text, CompletionGenerator); |
| 99 rl_attempted_completion_over = true; | 112 rl_attempted_completion_over = true; |
| 100 return result; | 113 return result; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 121 return strdup(*str); | 134 return strdup(*str); |
| 122 } else { | 135 } else { |
| 123 current_completions.Dispose(); | 136 current_completions.Dispose(); |
| 124 current_completions.Clear(); | 137 current_completions.Clear(); |
| 125 return NULL; | 138 return NULL; |
| 126 } | 139 } |
| 127 } | 140 } |
| 128 | 141 |
| 129 | 142 |
| 130 } // namespace v8 | 143 } // namespace v8 |
| OLD | NEW |