aboutsummaryrefslogtreecommitdiffhomepage
path: root/history.h
diff options
context:
space:
mode:
Diffstat (limited to 'history.h')
-rw-r--r--history.h142
1 files changed, 71 insertions, 71 deletions
diff --git a/history.h b/history.h
index 9bfb2a51..3d083acb 100644
--- a/history.h
+++ b/history.h
@@ -18,7 +18,7 @@ typedef std::vector<wcstring> path_list_t;
enum history_search_type_t {
/** The history searches for strings containing the given string */
HISTORY_SEARCH_TYPE_CONTAINS,
-
+
/** The history searches for strings starting with the given string */
HISTORY_SEARCH_TYPE_PREFIX
};
@@ -31,30 +31,30 @@ class history_item_t {
private:
explicit history_item_t(const wcstring &);
explicit history_item_t(const wcstring &, time_t, const path_list_t &paths = path_list_t());
-
+
/** Attempts to merge two compatible history items together */
bool merge(const history_item_t &item);
- /** The actual contents of the entry */
- wcstring contents;
-
- /** Original creation time for the entry */
- time_t creation_timestamp;
-
+ /** The actual contents of the entry */
+ wcstring contents;
+
+ /** Original creation time for the entry */
+ time_t creation_timestamp;
+
/** Paths that we require to be valid for this item to be autosuggested */
path_list_t required_paths;
-
+
public:
const wcstring &str() const { return contents; }
bool empty() const { return contents.empty(); }
-
+
/* Whether our contents matches a search term. */
bool matches_search(const wcstring &term, enum history_search_type_t type) const;
-
+
time_t timestamp() const { return creation_timestamp; }
-
+
const path_list_t &get_required_paths() const { return required_paths; }
-
+
bool operator==(const history_item_t &other) const {
return contents == other.contents &&
creation_timestamp == other.creation_timestamp &&
@@ -78,36 +78,36 @@ private:
/** Private creator */
history_t(const wcstring &pname);
-
+
/** Privately add an item */
void add(const history_item_t &item);
-
+
/** Destructor */
~history_t();
/** Lock for thread safety */
pthread_mutex_t lock;
-
+
/** Internal function */
void clear_file_state();
- /** The name of this list. Used for picking a suitable filename and for switching modes. */
- const wcstring name;
-
- /** New items. */
- std::vector<history_item_t> new_items;
+ /** The name of this list. Used for picking a suitable filename and for switching modes. */
+ const wcstring name;
+
+ /** New items. */
+ std::vector<history_item_t> new_items;
+
+ /** Deleted item contents. */
+ std::set<wcstring> deleted_items;
- /** Deleted item contents. */
- std::set<wcstring> deleted_items;
+ /** How many items we've added without saving */
+ size_t unsaved_item_count;
- /** How many items we've added without saving */
- size_t unsaved_item_count;
-
- /** The mmaped region for the history file */
- const char *mmap_start;
+ /** The mmaped region for the history file */
+ const char *mmap_start;
- /** The size of the mmap'd region */
- size_t mmap_length;
+ /** The size of the mmap'd region */
+ size_t mmap_length;
/** The type of file we mmap'd */
history_file_type_t mmap_type;
@@ -115,23 +115,23 @@ private:
/** Timestamp of when this history was created */
const time_t birth_timestamp;
- /** Timestamp of last save */
- time_t save_timestamp;
-
+ /** Timestamp of last save */
+ time_t save_timestamp;
+
void populate_from_mmap(void);
-
+
/** List of old items, as offsets into out mmap data */
std::vector<size_t> old_item_offsets;
-
+
/** Whether we've loaded old items */
bool loaded_old;
-
+
/** Loads old if necessary */
bool load_old_if_needed(void);
-
+
/** Deletes duplicates in new_items. */
void compact_new_items();
-
+
/** Saves history */
void save_internal();
@@ -139,38 +139,38 @@ private:
static history_item_t decode_item_fish_2_0(const char *base, size_t len);
static history_item_t decode_item_fish_1_x(const char *base, size_t len);
static history_item_t decode_item(const char *base, size_t len, history_file_type_t type);
-
+
public:
/** Returns history with the given name, creating it if necessary */
static history_t & history_with_name(const wcstring &name);
-
+
/** Determines whether the history is empty. Unfortunately this cannot be const, since it may require populating the history. */
bool is_empty(void);
-
+
/** Add a new history item to the end */
void add(const wcstring &str, const path_list_t &valid_paths = path_list_t());
/** Remove a history item */
void remove(const wcstring &str);
-
+
/** Add a new history item to the end */
void add_with_file_detection(const wcstring &str);
-
+
/** Saves history */
void save();
-
+
/** Irreversibly clears history */
void clear();
-
+
/** Populates from a bash history file */
void populate_from_bash(FILE *f);
-
+
/* Gets all the history into a string with ARRAY_SEP_STR. This is intended for the $history environment variable. This may be long! */
void get_string_representation(wcstring &str, const wcstring &separator);
-
+
/** Return the specified history at the specified index. 0 is the index of the current commandline. (So the most recent item is at index 1.) */
history_item_t item_at_index(size_t idx);
-
+
bool is_deleted(const history_item_t &item) const;
};
@@ -178,10 +178,10 @@ class history_search_t {
/** The history in which we are searching */
history_t * history;
-
+
/** Our type */
enum history_search_type_t search_type;
-
+
/** Our list of previous matches as index, value. The end is the current match. */
typedef std::pair<size_t, history_item_t> prev_match_t;
std::vector<prev_match_t> prev_matches;
@@ -191,14 +191,14 @@ class history_search_t {
/** The search term */
wcstring term;
-
+
/** Additional strings to skip (sorted) */
wcstring_list_t external_skips;
-
+
bool should_skip_match(const wcstring &str) const;
-
+
public:
-
+
/** Gets the search term */
const wcstring &get_term() const { return term; }
@@ -207,22 +207,22 @@ class history_search_t {
/** Finds the next search term (forwards in time). Returns true if one was found. */
bool go_forwards(void);
-
+
/** Finds the previous search result (backwards in time). Returns true if one was found. */
bool go_backwards(void);
-
+
/** Goes to the end (forwards) */
void go_to_end(void);
-
+
/** Returns if we are at the end. We start out at the end. */
bool is_at_end(void) const;
-
+
/** Goes to the beginning (backwards) */
void go_to_beginning(void);
-
+
/** Returns the current search result item. asserts if there is no current item. */
history_item_t current_item(void) const;
-
+
/** Returns the current search result item contents. asserts if there is no current item. */
wcstring current_string(void) const;
@@ -233,14 +233,14 @@ class history_search_t {
search_type(type),
term(str)
{}
-
+
/* Default constructor */
history_search_t() :
history(),
search_type(HISTORY_SEARCH_TYPE_CONTAINS),
term()
{}
-
+
};
@@ -266,31 +266,31 @@ struct file_detection_context_t {
/* Constructor */
file_detection_context_t(history_t *hist, const wcstring &cmd);
-
+
/* Determine which of potential_paths are valid, and put them in valid_paths */
int perform_file_detection();
-
+
/* The history associated with this context */
history_t *history;
-
+
/* The command */
wcstring command;
-
+
/* When the command was issued */
time_t when;
-
+
/* The working directory at the time the command was issued */
wcstring working_directory;
-
+
/* Paths to test */
path_list_t potential_paths;
-
+
/* Paths that were found to be valid */
path_list_t valid_paths;
-
+
/* Performs file detection. Returns 1 if every path in potential_paths is valid, 0 otherwise. If test_all is true, tests every path; otherwise stops as soon as it reaches an invalid path. */
int perform_file_detection(bool test_all);
-
+
/* Determine whether the given paths are all valid */
bool paths_are_valid(const path_list_t &paths);
};