Skip to content

Commit

Permalink
🐛 [bug]修复table滚动无效.
Browse files Browse the repository at this point in the history
  • Loading branch information
lanjingling0510 committed May 18, 2017
1 parent 05bb573 commit c60af50
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/azer-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function showAllVersionID() {
console.log(chalk.green('当前已有的bundle版本名称:'));
console.log(chalk.green('.........................'));
fileNames.forEach(name => {
console.log(`${name}\n`);
console.log(chalk.green(`\n${name}\n`));
});
console.log(chalk.green('.........................'));
}
Expand Down
6 changes: 3 additions & 3 deletions src/azer-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function renderAnalyzeResult(list) {
const allCompareSize = list.reduce((a, b) => a + b.compareSize, 0);
const allRankSize = list.reduce((a, b) => a + b.rankSize, 0);

let summaryBoxContent = ` All Size: ${filesize(allSize)}`;
let summaryBoxContent = `{|} All Size: ${filesize(allSize)}`;
if (allRankSize > 0) {
summaryBoxContent += chalk.red(` ↑ ${filesize(allRankSize)}`);
summaryBoxContent += chalk.red(` optimize: ${((allCompareSize - allSize) / allSize * 100).toFixed(2)}%`);
Expand All @@ -155,11 +155,11 @@ function renderAnalyzeResult(list) {
// 更新概览视图
function updateSummaryView () {
if (baseVersion) {
summaryBox.updateView(chalk.green('\n 目标版本:' + baseVersion));
summaryBox.updateView(chalk.green('目标版本:' + baseVersion + '\n'));
}

if (compareVersion) {
summaryBox.updateView(summaryBox.content + chalk.green('\n 对比版本:' + compareVersion));
summaryBox.updateView(summaryBox.content + chalk.green('对比版本:' + compareVersion));
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/azer-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,24 @@ async function showAllVersionID() {

let schema = [
{
type: 'list',
name: 'path',
type: 'checkbox',
name: 'paths',
message: promptMessage + '请选择要删除的版本',
default: 0,
default: [],
choices: choices,
},
];

const result = await inquirer.prompt(schema);

if (result.path) {
await fs.remove(result.path);
}
if (_.isEmpty(result.paths)) {
return Promise.reject('没有要删除的版本.');
};

await result.paths.map(async (path) => {
await fs.remove(path);
});

}


Expand Down
89 changes: 54 additions & 35 deletions src/util/blessed.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const baseTable = grid.set(
6,
4,
contrib.table,
makeList(' 📝 目标版本', [24]),
makeList([24]),
);

baseTable.updateView = data => {
Expand All @@ -33,7 +33,7 @@ const compareTable = grid.set(
6,
4,
contrib.table,
makeList(' 📝 对比版本', [30]),
makeList([30]),
);

compareTable.updateView = data => {
Expand All @@ -42,56 +42,55 @@ compareTable.updateView = data => {
};

// 分析视图
const analyzeTable = grid.set(0, 0, 9, 8, contrib.table, {
label: ' 🌈 对比分析视图',
fg: 'white',
selectedFg: 'white',
interactive: false,
columnSpacing: 1,
columnWidth: [30, 20, 20, 20],
});
const analyzeTable = grid.set(
0,
0,
9,
8,
blessed.listtable,
makeScrollList([30, 20, 20, 20]),
);

analyzeTable.updateView = data => {
analyzeTable.setData({
headers: ['File Name', 'Base Version', 'Compare Version', 'Rank'],
data: data,
});
const headers = ['File Name', 'Base Version', 'Compare Version', 'Rank'];
analyzeTable.setData([headers, ...data]);
screen.render();
};

// 总览视图
const summaryBox = grid.set(9, 0, 3, 8, blessed.box, {
label: ' 💖 统计',
tags: true,
padding: 1,
border: {
type: 'line'
type: 'line',
},
style: {
fg: 'white',
border: { fg: 'cyan' },
hover: { border: { fg: 'green' }, }
}
border: {fg: 'cyan'},
hover: {border: {fg: 'green'}},
},
});

summaryBox.updateView = (content) => {
summaryBox.updateView = content => {
summaryBox.content = content;
screen.render();
}
};

// 提示框
const tipBox = grid.set(3, 2, 4, 4, blessed.box, {
tags: true,
style: {
border: {
fg: 'white'
}
fg: 'white',
},
},
content: `
Welcome! 😘
DOWN/UP = Moves cursor between lines
ENTER = Select version
ESC, CTRL_C, q = Abort
`
`,
});

screen.key(['escape', 'q', 'C-c'], function(ch, key) {
Expand All @@ -102,33 +101,53 @@ screen.on('resize', function() {
baseTable.emit('attach');
compareTable.emit('attach');
analyzeTable.emit('attach');
summaryBox.emit('attach');
});

// 允许键盘操作
baseTable.focus();
compareTable.focus();

baseTable.focus();
screen.render();

function makeList(label, columnWidth) {
// 设置标签名
analyzeTable.setLabel(' 🌈 对比分析视图');
baseTable.setLabel(' 📝 目标版本');
compareTable.setLabel(' 📝 对比版本');

function makeScrollList(columnWidth) {
const options = makeList(columnWidth);
options.scrollable = true;
options.scrollbar = {ch: ' '};
options.style.scrollbar = {bg: 'green', fg: 'white'};
options.style.header = {fg: 'cyan'};
options.vi = true;
options.alwaysScroll = true;
options.mouse = true;
return options;
}

function makeList(columnWidth) {
const options = makeBox();
options.columnSpacing = 1;
options.noCellBorders = true;
options.align = 'left';
options.columnWidth = columnWidth;
options.interactive = true;
return options;
}

function makeBox() {
return {
vi: true,
tags: true,
mouse: true,
keys: true,
label: label,
columnSpacing: 1,
columnWidth: columnWidth,
tags: true,
// draggable: true,
border: {
type: 'line', // or bg
},
style: {
fg: 'white',
border: {fg: 'cyan'},
hover: {border: {fg: 'green'}},
scrollbar: {bg: 'green', fg: 'white'},
},
scrollbar: {ch: ' '},
};
}

Expand Down

0 comments on commit c60af50

Please sign in to comment.