1
- const initSession = require ( '../utils/init-session' ) ;
2
1
const { exec} = require ( 'child_process' ) ;
3
- const Session = require ( '../session' ) ;
4
-
2
+ const initSession = require ( '../utils/init-session' ) ;
5
3
6
4
module . exports = class Pane {
7
5
constructor ( { rows, cols, cwd, shell, shellArgs, splitDirection, activeUid, uid, parent} , rpc , fn ) {
@@ -31,9 +29,8 @@ module.exports = class Pane {
31
29
uid,
32
30
shell : session . shell ,
33
31
pid : session . pty . pid
34
- } ) ;
32
+ } ) ;
35
33
}
36
- console . log ( 'uid: ' , this . uid , 'childs:' , this . childs . size ) ;
37
34
fn ( this ) ;
38
35
} ) ;
39
36
}
@@ -49,48 +46,43 @@ module.exports = class Pane {
49
46
opts . uid = recorded . uid ;
50
47
opts . cwd = recorded . cwd ;
51
48
}
52
- new Pane ( opts , this . rpc , pane => {
53
- this . childs . add ( pane ) ;
54
- win . sessions . set ( pane . uid , pane ) ;
55
- pane . session . on ( 'data' , data => {
56
- this . rpc . emit ( 'session data' , { uid : pane . uid , data} ) ;
57
- } ) ;
49
+ this . childs . add ( new Pane ( opts , this . rpc , pane => {
50
+ win . sessions . set ( pane . uid , pane ) ;
51
+ pane . session . on ( 'data' , data => {
52
+ this . rpc . emit ( 'session data' , { uid : pane . uid , data} ) ;
53
+ } ) ;
58
54
59
- pane . session . on ( 'exit' , ( ) => {
60
- if ( ! pane . root ) {
61
- pane . parent . childs . delete ( pane ) ;
62
- if ( pane . childs . size >= 1 ) {
63
- console . log ( 'curentPaneUid: ' , pane . uid ) ;
64
- pane . childs . forEach ( child => {
65
- child . parent = pane . parent ;
66
- pane . parent . childs . add ( child ) ;
67
- } ) ;
68
- console . log ( 'parentUid: ' , pane . parent . uid ) ;
69
- console . log ( 'uid: ' , pane . parent . uid , 'childs:' , pane . parent . childs . size ) ;
70
- }
55
+ pane . session . on ( 'exit' , ( ) => {
56
+ if ( ! pane . root ) {
57
+ pane . parent . childs . delete ( pane ) ;
58
+ if ( pane . childs . size >= 1 ) {
59
+ pane . childs . forEach ( child => {
60
+ child . parent = pane . parent ;
61
+ pane . parent . childs . add ( child ) ;
62
+ } ) ;
71
63
}
72
- } ) ;
73
- if ( recorded ) {
74
- recorded . childs . forEach ( pane => {
75
- this . rpc . emit ( 'pane restore' , { uid : recorded . uid , pane} ) ;
76
- } ) ;
77
64
}
78
- } ) ;
65
+ } ) ;
66
+ if ( recorded ) {
67
+ recorded . childs . forEach ( pane => {
68
+ this . rpc . emit ( 'pane restore' , { uid : recorded . uid , pane} ) ;
69
+ } ) ;
70
+ }
71
+ } ) ) ;
79
72
}
80
73
81
74
lastChild ( ) {
82
75
let cpt = 0 ;
83
- let last = undefined ;
76
+ let last ;
84
77
this . childs . forEach ( child => {
85
78
cpt ++ ;
86
- console . log ( 'childUID: ' , child . uid ) ;
87
79
if ( cpt === this . childs . size ) {
88
80
last = child ;
89
81
}
90
82
} ) ;
91
- return last ;
83
+ return last ;
92
84
}
93
-
85
+
94
86
record ( fn ) {
95
87
const pid = this . session . pty . pid ;
96
88
exec ( `lsof -p ${ pid } | grep cwd | tr -s ' ' | cut -d ' ' -f9-` , ( err , cwd ) => {
@@ -101,17 +93,8 @@ module.exports = class Pane {
101
93
this . cwd = cwd ;
102
94
}
103
95
} ) ;
104
-
105
- let pane = { } ;
106
- if ( this . root === true ) {
107
- pane = { uid : this . uid , cwd : this . cwd , type : 'PANE' , root : this . root , childs : [ ] } ;
108
- } else {
109
- pane = { uid : this . uid , cwd : this . cwd , type : 'PANE' , root : this . root , direction : this . direction , childs : [ ] } ;
110
- }
111
- // if(!this.root) {
112
- // pane = {uid: this.uid, cwd: this.cwd, type: 'PANE', root: this.root, direction: this.direction, childs: []};
113
- // }
114
- // const pane = {uid: this.uid, cwd: this.cwd, type: 'PANE', root: this.root, direction: this.direction, childs: []};
96
+
97
+ const pane = { uid : this . uid , cwd : this . cwd , type : 'PANE' , root : this . root , direction : this . direction , childs : [ ] } ;
115
98
this . childs . forEach ( child => {
116
99
child . record ( state => {
117
100
pane . childs . push ( state ) ;
0 commit comments