Browse Source

Added a getlines function and modified a few things withe test text and buffer. I also made the build script and source script better

cameron
stew3254 3 years ago
parent
commit
724c09df19
  1. 6
      build.sh
  2. 2
      source.sh
  3. 18
      src/Buffer.cpp
  4. 1
      src/Buffer.h
  5. 6
      src/FileBrowser.cpp
  6. 1
      test.txt

6
build.sh

@ -1,5 +1,11 @@
#!/bin/bash
if [ ! -d obj ]; then
mkdir obj
fi
cd obj
g++ ../src/*.cpp -c
cd ..
if [ ! -d bin ]; then
mkdir bin
fi
g++ obj/*.o -o bin/FileBrowser

2
source.sh

@ -1 +1 @@
alias run="make 1>/dev/null && ./FileBrowser"
alias run="./build.sh && bin/FileBrowser"

18
src/Buffer.cpp

@ -14,6 +14,18 @@ void Buffer::display() const
}
}
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;
}
return lines;
}
bool Buffer::open(const string & new_file_name)
{
std::ifstream file(new_file_name);
@ -28,10 +40,6 @@ bool Buffer::open(const string & new_file_name)
std::string curr_p, line;
while(getline(file, line))
{
// Remove any newlines that are in the file.
for(auto char_loc = line.find_first_of('\n'); char_loc != -1; char_loc = line.find_first_of('\n'))
line.erase(char_loc, 1);
// Replace break tags with newlines.
for(auto char_loc = line.find("<br>"); char_loc != -1; char_loc = line.find("<br>"))
line.replace(char_loc, 4, "\n");
@ -71,7 +79,7 @@ bool Buffer::open(const string & new_file_name)
line = extra_text;
}
// Append any data left on this line to the current paragraph being read.
curr_p += line;
curr_p += " " + line;
}
// Push the contents of curr_p as it has the last paragraph in the file.

1
src/Buffer.h

@ -18,6 +18,7 @@ public:
void move_to_next_page();
void move_to_previous_page();
bool open(const std::string & file_name);
std::string* get_lines() const;
void set_window_height(int h) { window_height_ = h; }
private:

6
src/FileBrowser.cpp

@ -9,7 +9,7 @@ void FileBrowser::display()
const string long_separator(50, '-');
const string short_separator(8, '-');
system("cls || clear");
//system("cls || clear");
if (!error_message_.empty()) {
cout << "ERROR: " + error_message_ << endl;
@ -21,8 +21,10 @@ void FileBrowser::display()
cout << "<no file opened>\n";
else
cout << file_name << endl;
cout << long_separator << endl;
auto lines = buffer_.get_lines();
delete[] lines;
buffer_.display();
cout << long_separator << endl;
cout << " next previous open\n";

1
test.txt

@ -3,3 +3,4 @@
<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 contains some<br> problematic<p> tags.
Derp. Derp. Derp. Derp. Derp.
Loading…
Cancel
Save