stew3254 4 years ago
parent
commit
b3202c52d5
  1. 23
      src/Buffer.cpp
  2. 19
      src/Buffer.h
  3. 17
      src/FileBrowser.cpp
  4. 30
      test.txt

23
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] = v_lines_[line_num + ix_top_line_];
//cout << v_lines_[line_num] << endl;
++line_num;
}
//cout << "----------" << endl << endl;;
return lines;
}
@ -113,9 +118,9 @@ bool Buffer::open(const string & new_file_name)
return true;
}
bool go(int & link)
bool Buffer::go(int link)
{
string f_name = v_links[link - 1];
string f_name = v_links_[link - 1].second;
if(!open(f_name))
return false;
@ -124,7 +129,7 @@ bool go(int & link)
}
void back()
void Buffer::back()
{
}

19
src/Buffer.h

@ -13,40 +13,41 @@
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 go(int link);
void 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()
inline int Buffer::max_links()
{
//return v_links.length();
return 1;

17
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 << std::setw(4) << i+1 << " " << 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;
@ -57,7 +63,9 @@ void FileBrowser::execute_command(char command, bool & done)
error_message_ = "Could not open link " + link;
}
break;
}*/
}
*/
case 'n': {
buffer_.move_to_next_page();
break;
@ -89,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 eighth 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 fourteenth 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 twentieth 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 twenty sixth 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 thirty second 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