Skip to content

Commit

Permalink
Merge pull request #39 from teju85/window-support
Browse files Browse the repository at this point in the history
Window support
  • Loading branch information
teju85 authored Aug 6, 2019
2 parents 9eb6d43 + 72829fb commit 2480813
Show file tree
Hide file tree
Showing 14 changed files with 418 additions and 132 deletions.
9 changes: 6 additions & 3 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
* teditor
*teditor* is a terminal based editor, written from scratch in C++. More details
about this editor can be found [[https://teju85.github.io/blog/tags.html#teditor][here]].
* Supported OS's
This has been only tested on cygwin till now. Should work for unix-based
systems. If it doesn't build/work properly on them, fixes are most welcome.
* Pre-reqs
Very minimal set of pre-reqs are needed for this project!
Very minimal set of pre-reqs are needed for this project.
** Compile time
1. GNU-make (>= 4.2.1)
2. G++ (>= 5.4.0)
Expand All @@ -21,13 +24,13 @@ $ ./bin/teditor
#+END_SRC
NOTE: If you have customized your minttyrc for the user configured colors,
then your experience with the default colors may vary!!
* Generating documentation
* Developers
** Generating documentation
It is expected that one has installed doxygen for this purpose. Generated
documentation can then be found inside the folder 'html'.
#+BEGIN_SRC bash
$ make doc
#+END_SRC
* Developers
** Unit testing
Unit-tests are run via catch2.
#+BEGIN_SRC bash
Expand Down
50 changes: 50 additions & 0 deletions src/core/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,4 +932,54 @@ void Buffer::indent() {
else removeRegion(start, end);
}


Buffers::~Buffers() {
for(int i=0;i<(int)size();++i) {
erase(i);
--i;
}
buffNames.clear();
}

void Buffers::clear() {
std::vector<Buffer*>::clear();
buffNames.clear();
}

Buffer* Buffers::push_back(const std::string& name) {
auto uname = uniquify(name);
auto* buf = new Buffer(uname);
push_back(buf);
return buf;
}

void Buffers::push_back(Buffer* buf) {
std::vector<Buffer*>::push_back(buf);
buffNames.insert(buf->bufferName());
}

void Buffers::erase(int idx) {
Buffer* buf = at(idx);
buffNames.erase(buf->bufferName());
delete buf;
std::vector<Buffer*>::erase(begin() + idx);
}

Strings Buffers::namesList() const {
Strings ret;
for(const auto* buff : *this) ret.push_back(buff->bufferName());
return ret;
}

std::string Buffers::uniquify(const std::string& name) const {
std::string out(name);
auto start = buffNames.begin(), end = buffNames.end();
int idx = 0;
while(std::find(start, end, out) != end) {
++idx;
out = name + "_" + num2str(idx);
}
return out;
}

} // end namespace teditor
29 changes: 28 additions & 1 deletion src/core/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mode.h"
#include "pos2d.h"
#include <stack>
#include <vector>


namespace teditor {
Expand Down Expand Up @@ -195,8 +196,8 @@ class Buffer {
Positions saveCursors() const { return copyCursors(locs); }
/** restore the state of all cursors to the given one */
void restoreCursors(const Positions& pos);
/** cursor at i'th index */
const Pos2di& cursorAt(int i) const { return locs[i]; }
const Positions& cursors() const { return locs; }
/** @} */

/** length of a given line in this buffer */
Expand All @@ -217,6 +218,7 @@ class Buffer {
bool isModified() const { return modified; }
virtual int getMinStartLoc() const { return 0; }
std::string dirModeGetFileAtLine(int line);
int start() const { return startLine; }

/**
* @defgroup RegionOps Operations with regions
Expand All @@ -234,6 +236,7 @@ class Buffer {
void startRegion() { regions.enable(locs); }
/** stop the currently active mark (or region) */
void stopRegion() { regions.clear(); }
const Regions& getRegions() const { return regions; }
/** @} */

void reload();
Expand Down Expand Up @@ -386,4 +389,28 @@ class Buffer {
friend class Editor;
};


/** a list of buffers */
class Buffers : public std::vector<Buffer*> {
public:
~Buffers();

/** create a new buffer with a unique name and push it to the end */
Buffer* push_back(const std::string& name);

void clear();
void push_back(Buffer* buf);

/** list of buffer names, in the order they are found in this object */
Strings namesList() const;

/** erase buffer at the given index */
void erase(int idx);

private:
std::set<std::string> buffNames;

std::string uniquify(const std::string& name) const;
};

}; // end namespace teditor
Loading

0 comments on commit 2480813

Please sign in to comment.