Browse Source

Improved terminal links search

merge-requests/365/head
eidheim 10 years ago
parent
commit
e639087d3d
  1. 24
      src/terminal.cc
  2. 12
      src/terminal.h

24
src/terminal.cc

@ -4,17 +4,6 @@
#include "info.h" #include "info.h"
#include "notebook.h" #include "notebook.h"
#include <iostream> #include <iostream>
//Temporary fix for current Arch Linux boost linking problem
#ifdef __GNUC_PREREQ
#if __GNUC_PREREQ(5,1)
#include <regex>
#define REGEX_NS std
#endif
#endif
#ifndef REGEX_NS
#include <boost/regex.hpp>
#define REGEX_NS boost
#endif
Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) { Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {
start(start_msg); start(start_msg);
@ -51,6 +40,8 @@ void Terminal::InProgress::cancel(const std::string& msg) {
Terminal::get().async_print(line_nr-1, msg); Terminal::get().async_print(line_nr-1, msg);
} }
const REGEX_NS::regex Terminal::link_regex("^([A-Z]:)?([^:]+):([0-9]+):([0-9]+)$");
Terminal::Terminal() { Terminal::Terminal() {
bold_tag=get_buffer()->create_tag(); bold_tag=get_buffer()->create_tag();
bold_tag->property_weight()=PANGO_WEIGHT_BOLD; bold_tag->property_weight()=PANGO_WEIGHT_BOLD;
@ -206,8 +197,12 @@ void Terminal::apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter)
if(offset!=2) if(offset!=2)
#endif #endif
++colons; ++colons;
if(colons==3 && possible_path) if(colons==3 && possible_path) {
get_buffer()->apply_tag(link_tag, start_path_iter, iter); REGEX_NS::smatch sm;
if(REGEX_NS::regex_match(get_buffer()->get_text(start_path_iter, iter).raw(), sm, link_regex))
get_buffer()->apply_tag(link_tag, start_path_iter, iter);
possible_path=false;
}
} }
} }
} }
@ -355,9 +350,8 @@ bool Terminal::on_button_press_event(GdkEventButton* button_event) {
if(iter.has_tag(link_tag) && if(iter.has_tag(link_tag) &&
start_iter.backward_to_tag_toggle(link_tag) && end_iter.forward_to_tag_toggle(link_tag)) { start_iter.backward_to_tag_toggle(link_tag) && end_iter.forward_to_tag_toggle(link_tag)) {
std::string path_str=get_buffer()->get_text(start_iter, end_iter); std::string path_str=get_buffer()->get_text(start_iter, end_iter);
const static REGEX_NS::regex path_regex("^([A-Z]:)?([^:]+):([0-9]+):([0-9]+)$");
REGEX_NS::smatch sm; REGEX_NS::smatch sm;
if(REGEX_NS::regex_match(path_str, sm, path_regex)) { if(REGEX_NS::regex_match(path_str, sm, link_regex)) {
auto path_str=sm[1].str()+sm[2].str(); auto path_str=sm[1].str()+sm[2].str();
auto path=boost::filesystem::path(path_str); auto path=boost::filesystem::path(path_str);
boost::system::error_code ec; boost::system::error_code ec;

12
src/terminal.h

@ -11,6 +11,17 @@
#include "process.hpp" #include "process.hpp"
#include "dispatcher.h" #include "dispatcher.h"
#include <unordered_set> #include <unordered_set>
//Temporary fix for current Arch Linux boost linking problem
#ifdef __GNUC_PREREQ
#if __GNUC_PREREQ(5,1)
#include <regex>
#define REGEX_NS std
#endif
#endif
#ifndef REGEX_NS
#include <boost/regex.hpp>
#define REGEX_NS boost
#endif
class Terminal : public Gtk::TextView { class Terminal : public Gtk::TextView {
public: public:
@ -63,6 +74,7 @@ private:
Glib::RefPtr<Gdk::Cursor> link_mouse_cursor; Glib::RefPtr<Gdk::Cursor> link_mouse_cursor;
Glib::RefPtr<Gdk::Cursor> default_mouse_cursor; Glib::RefPtr<Gdk::Cursor> default_mouse_cursor;
size_t deleted_lines=0; size_t deleted_lines=0;
const static REGEX_NS::regex link_regex;
void apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter); void apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter);
std::vector<std::shared_ptr<Process> > processes; std::vector<std::shared_ptr<Process> > processes;

Loading…
Cancel
Save