Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More unused header removal #406

Closed
wants to merge 9 commits into from

Conversation

jkoutavas
Copy link
Contributor

Another baby step towards an embeddable iTerm2 library.

Sorry about the redundant commits in this PR, I had a bit of a cockpit error while rebasing my fork's master branch to your master branch. Though I'm an old hand at git and github, I'm kind of new at cross-fork PR submissions.

@gnachman
Copy link
Owner

Some of these shouldn't be removed. My goal is to follow the "include what you use" rule (https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md).

For example, PTYSession.m imports iTermFindDriver.h because it conforms to iTermFindDriverDelegate. This PR proposes to remove it. That means it is imported indirectly from LineBuffer.h importing FindContext.h importing iTermFindDriver.h. If I refactor FindContext.h to not depend on that file any more then it will rather mysteriously break code that imports PTYSession.h.

@jkoutavas
Copy link
Contributor Author

jkoutavas commented Oct 13, 2019

Okay, good point. I'll apply more due diligence as I progress as I delve deeper into dividing "view from app"

…h, these imports are part of PTYSession's conformance declaration (applying "include what you use")
Copy link
Owner

@gnachman gnachman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking better, but still a few issues. I love fixing the headers (there was not very good header hygiene for the first 15 years of development), but it's hard to get right. Let me know what your big picture plan is and I might be able to help point you in the right direction.

@@ -1,28 +1,23 @@
// Implements the model class for a terminal session.

#import "Api.pbobjc.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in this file. For example, ITMGetBufferResponse. Anything with the ITM prefix comes from the protobufs. However, since only objects are ever referenced this import could be replaced with forward references like @class ITMGetBufferResponse for each referenced symbol.

#import "DVR.h"
#import "iTermAPIHelper.h"
#import "iTermEchoProbe.h"
#import "iTermFindDriver.h"
#import "iTermFileDescriptorClient.h"
#import "iTermMetalUnavailableReason.h"
#import "iTermWeakReference.h"
#import "ITAddressBookMgr.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses iTermSessionEndAction from this include.

#import "PTYTask.h"
#import "PTYTextView.h"
#import "ProfileModel.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the Profile macro in this file, which is defined in ProfileModel.h

#import "TextViewWrapper.h"
#import "TmuxController.h"
#import "TmuxGateway.h"
#import "VT100Screen.h"
#import "VT100ScreenMark.h"
#import "WindowControllerInterface.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can replace this with @interface WindowControllerInterface, which is used below

@@ -26,7 +26,6 @@
*/

#import <Cocoa/Cocoa.h>
#import "iTermFindDriver.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SessionView conforms to the iTermFindDriverDelegate protocol declared in this header

@jkoutavas
Copy link
Contributor Author

jkoutavas commented Oct 20, 2019

Okay, I'll roll these back.

The "big picture plan" has evolved since I started. I originally was hoping to separate-out an iTerm "ViewKit" library, which had everything necessary to provide an iTerm2 view without any window dressing or auxiliary view controllers (Preferences, WindowController, etc.), even foregoing Python scripting capabilities, along the lines of "Phase 2" that I brought up in PR #366. As I've dived in deeper, now I'm starting to see how tightly coupled these things are, and am considering just "lumping it all together" like PR #366 tried to do (and what my Phase 1 described). And then, maybe abstract-out the auxiliary view controllers after that.

The bulk of my work is currently in a local git repo called "IT2ViewKit" which uses cmake to divide things up into nice layers like "IT2Foundation", "IT2Scripting", and IT2ViewKit". Using cmake is great because it doesn't require I touch iTerm's existing xcode project at all, nor even have to commit to an "iTerm2Lib" xcode project. Cmake can generate projects at will.

Maybe, even further down the road, when my project is well underway, I may submit a PR that uses cmake to build everything, including iTerm2.app. A PR that does not require committing even iTerm2.xcodeproj to the repo. But, that's jsut pie-in-the-sky for me right now.

@gnachman
Copy link
Owner

Decoupling things will be a necessary part of making it possible to create a library. I'm fine with using cmake but I don't know how to prevent breaking things as changes are made. I suppose when a new file is added both the xcode project and the makefile will need to be updated together?

@jkoutavas
Copy link
Contributor Author

jkoutavas commented Oct 27, 2019

I suppose when a new file is added both the xcode project and the makefile will need to be updated together?

Yeah, pretty much like that. I'm hoping to achieve the goal of making that really easy and understandable when the time comes to present that PR.

At the moment, I'm trying to find a clean way to avoid inclusion of iTermAPIHelper in the view library. iTermAPIHelper.m imports modules from all over the place. I think I can nip it off at ITermObject.

@gnachman
Copy link
Owner

gnachman commented Nov 1, 2019

At the moment, I'm trying to find a clean way to avoid inclusion of iTermAPIHelper in the view library. iTermAPIHelper.m imports modules from all over the place. I think I can nip it off at ITermObject.

I think any attempt at cleanly separating views out from other stuff will require adding a lot of new protocols. Right now the dependency graph is full of cycles because I've been optimizing for velocity over flexibility. I could imagine a world where the API helper is a delegate of the various classes that call directly into it, and then they could tolerate its non-existence.

@jkoutavas
Copy link
Contributor Author

jkoutavas commented Nov 12, 2019

@gnachman, it's been a few days since my last comment re:Big Picture. Let me fill you in on what I've been to.

I paused my work on sorting-out the headers and focused on ensuring that "iTerm2Lib" will be the right solution for my project. The area I'm exploring right now is "how to trick iTerm2Lib into using a pty driver that does a remote connection to a server." You see, I want to use /just/ the text rendering aspects of iTerm2, I'm not interested in opening a local shell, I'm interested in opening a connection to a remote MUD server. I'm thinking I could make a custom pty process/driver that connects to the server and then have iTerm2Lib open that pty session. Problem is, I'm new to dealing with tty/pty dev concepts and am not sure if even such a thing is possible. I'm a little out of my experience zone here. Do you know much about this subject? Do you think I'm taking the right approach of redirecting at the pty level like this? Is there an easier approach?

Originally, I started my Savitar v2.0 project using attributed strings sent to an NSTextView. But, I was concerned about performance, so I got attracted to the idea of using an embeddable iTerm2 view instead (yay, Metal!) Besides, iTerm2 also has triggering support, ANSI color code support, and a few other things that I wouldn't have to implement for myself atop of NSTextView (not that I haven't already implemented all of this already in v1.0 of my project.)

@gnachman
Copy link
Owner

I made a rough sketch of how to refactor PTYTask to enable this in the refactor_ptytask branch. That branch is not shippable because it has bugs. If we're going to make this real the refactor will need to proceed methodically and probably add some unit tests. I'll continue to work on it because I will need this for an upcoming change to reduce the number of daemon processes.

@jkoutavas
Copy link
Contributor Author

I made a rough sketch of how to refactor PTYTask to enable this in the refactor_ptytask branch.

I looked over this branch a few days ago, but I didn't see how I might be able to reuse things to do a remote socket. Is such a thing possible?

Maybe instead of integrating a socket, I have the session do the remote connect as part of its "shell" script?

@gnachman
Copy link
Owner

Good news, I've landed that change.

You need to write a class that implements iTermJobManager. You don't need to implement attachToServer:withProcessID:task: as long as isSessionRestorationPossible returns NO.

The most important thing is to vend a file descriptor in your -fd method and to implement forkAndExecWithTtyState:… to create a new connection. Use iTermLegacyJobManager as your model, since it's simple-ish.

Maybe instead of integrating a socket, I have the session do the remote connect as part of its "shell" script?

What do you mean by "'shell' script"? If you mean replacing its shell ivar with an implementation other than PTYTask I don't recommend that.

Copy link

@soheil soheil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok nice

@@ -30,7 +30,6 @@
#import "iTermMalloc.h"
#import "iTermSwiftyStringParser.h"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -30,7 +30,6 @@
#import "iTermAdvancedSettingsModel.h"
#import "iTermScrollAccumulator.h"
#import "NSView+iTerm.h"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -1,28 +1,23 @@
// Implements the model class for a terminal session.

#import "Api.pbobjc.h"
#import "DVR.h"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -26,7 +26,6 @@
*/

#import <Cocoa/Cocoa.h>
#import "iTermFindDriver.h"
#import "iTermMetalDriver.h"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -24,7 +24,6 @@
#import "PTYScrollView.h"
#import "PTYSession.h"
#import "PTYTab.h"
#import "PTYTextView.h"
#import "PTYWindow.h"
#import "SessionTitleView.h"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@gnachman gnachman closed this Sep 27, 2024
@mikeknack86
Copy link

Ok

@mikeknack86
Copy link

Details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants