Cameron Weinfurt 3 years ago
parent
commit
8e88b1038a
  1. 34
      src/Buffer.cpp
  2. 22
      src/Buffer.h
  3. 23
      src/FileBrowser.cpp
  4. 30
      test.txt

34
src/Buffer.cpp

@ -4,25 +4,30 @@
using namespace std;
/*
void Buffer::display() const
{
int ix_stop_line_ = ix_top_line_ + window_height_;
int ix_stop_line_ = ix_top_line_ + window_height;
for (int i = ix_top_line_; i < ix_stop_line_; ++i) {
if (i < v_lines_.size())
cout << std::setw(6) << i+1 << " " << v_lines_[i];
cout << '\n';
}
}
*/
string* Buffer::get_lines() const
{
string* lines = new string[window_height_];
int line = 0;
while (line < window_height_ && line + ix_top_line_ < v_lines_.size()) {
lines[line - ix_top_line_] = v_lines_[line];
++line;
string* lines = new string[window_height];
int line_num = 0;
while (line_num < window_height && line_num + ix_top_line_ < v_lines_.size()) {
lines[line_num - ix_top_line_] = v_lines_[line_num];
//cout << v_lines_[line_num] << endl;
++line_num;
}
//cout << "----------" << endl << endl;;
return lines;
}
@ -112,3 +117,20 @@ bool Buffer::open(const string & new_file_name)
ix_top_line_ = 0;
return true;
}
bool Buffer::go(int link)
{
string f_name = v_links_[link - 1].second;
if(!open(f_name))
return false;
else
return true;
}
void Buffer::back()
{
}

22
src/Buffer.h

@ -13,34 +13,44 @@
class Buffer
{
public:
void display() const;
//void display() const;
const std::string & file_name() const { return file_name_; }
void move_to_next_page();
void move_to_previous_page();
int max_links();
bool go(int & link);
back();
bool open(const std::string & file_name);
std::string* get_lines() const;
void set_window_height(int h) { window_height_ = h; }
void set_window_height(int h) { window_height = h; }
//Made window height public so the display function can be removed
int window_height = 0;
private:
std::vector<std::string> v_lines_;
std::vector<std::pair<std::string, std::string>> v_links_;
int ix_top_line_ = 0;
std::string file_name_;
int window_height_;
};
inline void Buffer::move_to_next_page()
{
ix_top_line_ += window_height_;
ix_top_line_ += window_height;
if (ix_top_line_ >= v_lines_.size())
ix_top_line_ -= window_height_;
ix_top_line_ -= window_height;
}
inline void Buffer::move_to_previous_page()
{
ix_top_line_ -= window_height_;
ix_top_line_ -= window_height;
if (ix_top_line_ < 0)
ix_top_line_ = 0;
}
inline int Buffer::max::links()
{
//return v_links.length();
return 1;
}
#endif

23
src/FileBrowser.cpp

@ -23,9 +23,13 @@ void FileBrowser::display()
cout << file_name << endl;
cout << long_separator << endl;
//Display the lines
auto lines = buffer_.get_lines();
for (int i = 0; i < buffer_.window_height; ++i)
cout << lines[i] << endl;
delete[] lines;
buffer_.display();
//buffer_.display();
cout << long_separator << endl;
cout << " next previous open\n";
cout << " go back quit\n";
@ -35,10 +39,12 @@ void FileBrowser::display()
void FileBrowser::execute_command(char command, bool & done)
{
switch (command) {
/*case 'b': {
/*
case 'b': {
buffer_.back();
break;
}
case 'g': {
stringstream ss;
string temp;
@ -48,14 +54,18 @@ void FileBrowser::execute_command(char command, bool & done)
ss.str(temp);
ss >> link;
if (!ss) {
error_message_ = "Could not open " + temp;
error_message_ = temp + " is not a valid link";
}
if (link < 1 || link > buffer_.max_links()) {
error_message_ = "Could not open " + temp + " because the file is out of range";
}
buffer_.go(link);
if(!buffer_.go(link)){
error_message_ = "Could not open link " + link;
}
break;
}*/
}
*/
case 'n': {
buffer_.move_to_next_page();
break;
@ -87,13 +97,12 @@ void FileBrowser::run()
cout << "Window height? ";
cin >> window_height_;
cin.get(); // '\n'
cout << '\n';
buffer_.set_window_height(window_height_);
cout << "Maximum length? ";
cin >> maximum_length_;
cin.get(); // '\n'
cout << '\n';
cout << endl;
bool done = false;
while (!done) {

30
test.txt

@ -4,3 +4,33 @@
<p>This line is split into <p>two paragraph tags.
<p>This line con<br>tains some<br > problematic< p> tags.
Derp. Derp. Derp. Derp. Derp.
<p>This is the first line in the file.
<p>This is the second <br> and third line of the file.
<p>This line has a link to the <a docs/specification.txt specification> file.
<p>This line is split into <p>two paragraph tags.
<p>This line con<br>tains some<br > problematic< p> tags.
Derp. Derp. Derp. Derp. Derp.
<p>This is the first line in the file.
<p>This is the second <br> and third line of the file.
<p>This line has a link to the <a docs/specification.txt specification> file.
<p>This line is split into <p>two paragraph tags.
<p>This line con<br>tains some<br > problematic< p> tags.
Derp. Derp. Derp. Derp. Derp.
<p>This is the first line in the file.
<p>This is the second <br> and third line of the file.
<p>This line has a link to the <a docs/specification.txt specification> file.
<p>This line is split into <p>two paragraph tags.
<p>This line con<br>tains some<br > problematic< p> tags.
Derp. Derp. Derp. Derp. Derp.
<p>This is the first line in the file.
<p>This is the second <br> and third line of the file.
<p>This line has a link to the <a docs/specification.txt specification> file.
<p>This line is split into <p>two paragraph tags.
<p>This line con<br>tains some<br > problematic< p> tags.
Derp. Derp. Derp. Derp. Derp.
<p>This is the first line in the file.
<p>This is the second <br> and third line of the file.
<p>This line has a link to the <a docs/specification.txt specification> file.
<p>This line is split into <p>two paragraph tags.
<p>This line con<br>tains some<br > problematic< p> tags.
Derp. Derp. Derp. Derp. Derp.
Loading…
Cancel
Save