Location>code7788 >text

Implementing a terminal text editor to learn the golang language

Popularity:437 ℃/2024-08-03 16:07:17


Welcome! This series of blog posts will take you through writing a text editor of your own using the golang language.

I'd like to start by saying what motivated me to write this series of posts.

In fact, as a school enrollment to join a head of the Internet factory has been almost 4 years. It can be said that the factory is considered to be relatively early with the golang language as the main back-end development technology stack of the company, the vast majority of the back-end project language selection is golang. recent year will find that many of the core project are trying to use rust language to rewrite. The reason for this is that after a long period of iteration and optimization, the performance of golang has been fully drained, and in the environment of cost reduction and efficiency, some breakthrough technology is needed to further improve the performance of the service while hardware resources remain unchanged (or to reduce the consumption of hardware resources as much as possible while the performance of the current service remains unchanged), so rust naturally enters everyone's field of vision. The bigwigs in the company also showed their skills to reconfigure the service rust, and eventually got a good profit.

I naturally also have a strong interest in rust, interested in learning some, understand the characteristics of its individual after the thought of going to practice, test their own learning results. So I found thisRust-based text editorThe project, following the article step by step handwritten down, has been very rewarding and has led to a deeper understanding of RUST.

A little skewed topic back to the main topic, take rust after writing is not yet finished, coincided with some business adjustments intended to change jobs, in the finalization of the receiving department and began to go after the process of living water, got a rare few weeks of respite, so I thought to take advantage of this time with the golang language to the text editor to realize it again from scratch. Finally spent three days, drawing on some of the ideas in the above project, wrote a simple version of the text editor (display, edit, save functions). In fact, this kind of small project is more suitable to be used to familiarize with a programming language, so I decided to put how to build from scratch anSmall-scale recreation toThe editor is given a record to share for your reference and learning. Of course for those readers who already know golang but are confused about the ins and outs of text editor implementation, this series of articles is also for you.

To summarize, this series of posts will guide you through multiple small assignments to build the editor and gain a deeper understanding of the golang language.It is assumed here that you already have some knowledge of golang syntax. In most steps, you can compile and run the program to see the changes made. In my opinion.Simply enter the code and observe the resultsI'm sure you'll be able to learn a lot from it. I'll give you code examples (not necessarily the optimal way to write them) for each of these small assignments as commits for your reference, and of course you're highly encouraged to try them out on your own and compare them to mine. The final implementation is shown above. At present, it only supports basic display, editing and saving functions, and if we have time later, we will add more functions, such as searching, highlighting and other capabilities.

The source code for this project I've put on my github under the namezedtermThe first chapter of the book has a corresponding branch, and each assignment has a corresponding commit. Each chapter has a corresponding branch, each job has a corresponding commit. currently only updated to the text view function, expected to be in mid-August to take care of the editing and saving functions. This is a basic text editor has taken shape.