Skip to content

Commit d5187bb

Browse files
committed
refactor: update some features
1 parent b839e82 commit d5187bb

File tree

20 files changed

+568
-121
lines changed

20 files changed

+568
-121
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
一款AI驱动的祖传代码炼金师,将优雅代码『精心』重构为屎山💩。An AI-powered legacy code alchemist that carefully transforms clean code into shit code.
33

44
## 简介
5+
> 还在担心 AI 时代抢走你的饭碗? 那就用魔法打败魔法。
6+
-- 鲁迅
7+
58
ShitCodify是一个能够将正常、易读、易维护的代码转换为难以理解、难以维护但仍然能够正常工作的"屎山代码"的工具。它利用大型语言模型(如GPT-4)来分析你的代码,并应用各种"反模式"和不良实践来降低代码的可读性和可维护性,同时保持代码的功能不变。
69

710
## 为什么需要这个工具?
811
- 工作保障计划: 确保你的代码像谜题一样存在, 提升你在公司不可替代的地位
912
- 职场关系优化:让代码评审变成「你猜我在写什么」的悬疑社交游戏, 强迫产品经理理解技术负债的价值
1013
- 时间加速器:10分钟体验10年屎山沉积的「包浆」质感
1114
- 学习反面案例: 展示不良编程习惯的影响
12-
等等...
15+
- ...
1316

1417
## 特性
1518
- 支持多种编程语言(Rust、Python、JavaScript、Java、C++、Go、Ocaml等)
@@ -26,12 +29,32 @@ ShitCodify是一个能够将正常、易读、易维护的代码转换为难以
2629
直接访问 https://stepfenshawn.github.io/ShitCodify/#/ 生成 Prompt 后将其复制给大模型使用。
2730

2831
## Build
32+
```sh
33+
git clone [email protected]:StepfenShawn/ShitCodify.git
34+
cd ShitCodify
2935
```
36+
运行:
37+
```sh
3038
npm install
3139
npm run dev
3240
```
41+
部署:
42+
```sh
43+
npm run build
44+
```
45+
46+
## 贡献 Prompts
47+
所有语言的 prompts 模板在 [这个](src/prompt/) 目录下.
48+
欢迎贡献代码、报告问题或提出建议!
3349

3450
## 后续
35-
- 优化 Prompt.
51+
- 支持更多语言的特定 Prompt 和优化 Prompt.
3652
- 用 Rust 实现 CLI 和支持调用本地模型.
37-
- 实现 AI Agent.
53+
- 实现 AI Agent, 实现类似 cursor 的屎山代码助手, 可以快速构建出屎山项目.
54+
55+
## 免责声明
56+
本工具仅供学习和娱乐目的使用。请不要在生产环境或重要项目中使用生成的"屎山代码"。作者不对因使用本工具生成的代码而导致的任何问题负责。
57+
58+
## 许可证
59+
本项目采用MIT许可证。
60+

src/App.vue

Lines changed: 123 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const selectedLanguage = ref('javascript');
1414
const projectFiles = ref<FileNode[]>([]);
1515
const selectedFile = ref<FileNode | null>(null);
1616
const showConfigModal = ref(false);
17+
const showSidebar = ref(true); // 控制侧边栏显示状态
1718
1819
// 计算属性
1920
const canConvert = computed(() => sourceCode.value.trim().length > 0);
2021
const selectedFilePath = computed(() => selectedFile.value?.path || '');
22+
const hasSidebar = computed(() => projectFiles.value.length > 0 && showSidebar.value);
2123
2224
// 配置
2325
const config = reactive({
@@ -73,6 +75,9 @@ const handleFileUpload = (files: File[]) => {
7375
// 添加到文件树
7476
projectFiles.value = [fileToNode(file)];
7577
selectedFile.value = projectFiles.value[0];
78+
79+
// 确保侧边栏显示
80+
showSidebar.value = true;
7681
}
7782
};
7883
reader.readAsText(file);
@@ -85,6 +90,9 @@ const handleFileUpload = (files: File[]) => {
8590
if (firstFile) {
8691
selectedFile.value = firstFile;
8792
loadFileContent(firstFile, files);
93+
94+
// 确保侧边栏显示
95+
showSidebar.value = true;
8896
}
8997
}
9098
};
@@ -177,13 +185,18 @@ const setLanguageFromExtension = (extension: string) => {
177185
}
178186
};
179187
180-
// const handleLanguageChange = (language: string) => {
181-
// selectedLanguage.value = language;
182-
// };
188+
// 切换侧边栏显示状态
189+
const toggleSidebar = () => {
190+
showSidebar.value = !showSidebar.value;
191+
};
192+
193+
const handleLanguageChange = (language: string) => {
194+
selectedLanguage.value = language;
195+
};
183196
184-
// const handleConfigChange = (newConfig: any) => {
185-
// config.shitty_code_settings = newConfig.shitty_code_settings;
186-
// };
197+
const handleConfigChange = (newConfig: any) => {
198+
config.shitty_code_settings = newConfig.shitty_code_settings;
199+
};
187200
188201
const closeConfigModal = () => {
189202
showConfigModal.value = false;
@@ -201,16 +214,32 @@ const closeConfigModal = () => {
201214
<!-- 主内容区域 -->
202215
<div class="main-content">
203216
<!-- 侧边栏 -->
204-
<div class="sidebar" v-if="projectFiles.length > 0">
217+
<div class="sidebar" v-if="hasSidebar">
218+
<div class="sidebar-header">
219+
<h3>项目文件</h3>
220+
<button class="sidebar-toggle" @click="toggleSidebar" title="隐藏侧边栏">
221+
<span>◀</span>
222+
</button>
223+
</div>
205224
<FileTree
206225
:files="projectFiles"
207226
@file-select="handleFileSelect"
208227
:selected-path="selectedFilePath"
209228
/>
210229
</div>
211230

231+
<!-- 侧边栏切换按钮 -->
232+
<button
233+
v-if="projectFiles.length > 0 && !showSidebar"
234+
class="sidebar-show-button"
235+
@click="toggleSidebar"
236+
title="显示侧边栏"
237+
>
238+
<span>▶</span>
239+
</button>
240+
212241
<!-- 编辑器区域 -->
213-
<div class="editors">
242+
<div class="editors" :class="{ 'with-sidebar': hasSidebar }">
214243
<div class="editor-container">
215244
<CodeEditor
216245
v-model="sourceCode"
@@ -282,15 +311,80 @@ html, body {
282311
overflow: hidden;
283312
width: 100%;
284313
height: calc(100vh - 60px);
314+
position: relative;
285315
}
286316
287317
.sidebar {
288318
width: 250px;
289319
min-width: 200px;
290-
overflow: auto;
320+
overflow: hidden;
291321
border-right: 1px solid #333;
292322
background-color: #1e1e1e;
293323
height: 100%;
324+
display: flex;
325+
flex-direction: column;
326+
transition: width 0.3s ease;
327+
}
328+
329+
.sidebar-header {
330+
display: flex;
331+
justify-content: space-between;
332+
align-items: center;
333+
padding: 10px 16px;
334+
background-color: #2a2a2a;
335+
border-bottom: 1px solid #333;
336+
}
337+
338+
.sidebar-header h3 {
339+
margin: 0;
340+
font-size: 16px;
341+
font-weight: 500;
342+
}
343+
344+
.sidebar-toggle {
345+
background: none;
346+
border: none;
347+
color: #888;
348+
cursor: pointer;
349+
font-size: 14px;
350+
padding: 4px;
351+
display: flex;
352+
align-items: center;
353+
justify-content: center;
354+
border-radius: 4px;
355+
transition: all 0.2s ease;
356+
}
357+
358+
.sidebar-toggle:hover {
359+
color: #e0e0e0;
360+
background-color: #3a3a3a;
361+
}
362+
363+
.sidebar-show-button {
364+
position: absolute;
365+
left: 0;
366+
top: 50%;
367+
transform: translateY(-50%);
368+
background-color: #2a2a2a;
369+
border: none;
370+
border-right: 1px solid #333;
371+
color: #888;
372+
cursor: pointer;
373+
font-size: 14px;
374+
padding: 8px 4px;
375+
display: flex;
376+
align-items: center;
377+
justify-content: center;
378+
border-top-right-radius: 4px;
379+
border-bottom-right-radius: 4px;
380+
z-index: 5;
381+
transition: all 0.2s ease;
382+
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
383+
}
384+
385+
.sidebar-show-button:hover {
386+
color: #e0e0e0;
387+
background-color: #3a3a3a;
294388
}
295389
296390
.editor-container {
@@ -310,6 +404,12 @@ html, body {
310404
overflow: hidden;
311405
height: 100%;
312406
width: 100%;
407+
transition: width 0.3s ease, margin-left 0.3s ease;
408+
padding-left: 0;
409+
}
410+
411+
.editors.with-sidebar {
412+
width: calc(100% - 250px);
313413
}
314414
315415
.editor-panel {
@@ -451,10 +551,24 @@ html, body {
451551
border-bottom: 1px solid #333;
452552
}
453553
554+
.editors.with-sidebar {
555+
width: 100%;
556+
height: calc(100% - 200px);
557+
}
558+
454559
.editor-container {
455560
width: 100%;
456561
height: calc(100% - 200px);
457562
padding: 8px;
458563
}
564+
565+
.sidebar-show-button {
566+
top: 200px;
567+
left: 50%;
568+
transform: translateX(-50%) rotate(90deg);
569+
border-radius: 0 0 4px 4px;
570+
border-right: none;
571+
border-top: 1px solid #333;
572+
}
459573
}
460574
</style>

src/components/CodeEditor.vue

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</template>
3636

3737
<script setup lang="ts">
38-
import { ref, onMounted, watch, defineProps, defineEmits } from 'vue';
38+
import { ref, onMounted, onUnmounted, watch, defineProps, defineEmits } from 'vue';
3939
import * as monaco from 'monaco-editor';
4040
4141
const props = defineProps({
@@ -87,21 +87,52 @@ onMounted(() => {
8787
scrollBeyondLastLine: false,
8888
readOnly: props.readOnly,
8989
fontSize: 14,
90+
lineHeight: 21,
91+
fontFamily: "'Consolas', 'Monaco', 'Courier New', monospace",
9092
lineNumbers: 'on',
9193
renderLineHighlight: 'all',
9294
tabSize: 2,
9395
wordWrap: 'on',
94-
padding: { top: 10 }
96+
padding: { top: 10 },
97+
fixedOverflowWidgets: true,
98+
renderWhitespace: 'selection',
99+
guides: {
100+
indentation: true
101+
}
95102
});
96103
97104
editor.onDidChangeModelContent(() => {
98105
if (editor) {
99106
emit('update:modelValue', editor.getValue());
100107
}
101108
});
109+
110+
setTimeout(() => {
111+
if (editor) {
112+
editor.layout();
113+
}
114+
}, 100);
115+
116+
window.addEventListener('resize', handleResize);
117+
}
118+
});
119+
120+
onUnmounted(() => {
121+
// 移除窗口大小变化的监听器
122+
window.removeEventListener('resize', handleResize);
123+
124+
// 销毁编辑器
125+
if (editor) {
126+
editor.dispose();
102127
}
103128
});
104129
130+
const handleResize = () => {
131+
if (editor) {
132+
editor.layout();
133+
}
134+
};
135+
105136
watch(() => props.modelValue, (newValue) => {
106137
if (editor && newValue !== editor.getValue()) {
107138
editor.setValue(newValue);
@@ -238,6 +269,35 @@ const handleFileUpload = (event: Event) => {
238269
height: 100% !important;
239270
}
240271
272+
:deep(.monaco-editor .view-lines) {
273+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
274+
letter-spacing: 0 !important;
275+
text-align: left !important;
276+
}
277+
278+
:deep(.monaco-editor .lines-content) {
279+
align-items: flex-start !important;
280+
justify-content: flex-start !important;
281+
text-align: left !important;
282+
}
283+
284+
:deep(.monaco-editor .cursor) {
285+
width: 2px !important;
286+
}
287+
288+
:deep(.monaco-editor-background) {
289+
background-color: #1e1e1e !important;
290+
}
291+
292+
:deep(.monaco-editor .view-line) {
293+
width: 100% !important;
294+
text-align: left !important;
295+
}
296+
297+
:deep(.monaco-editor .view-line span) {
298+
text-align: left !important;
299+
}
300+
241301
@media (max-width: 768px) {
242302
.editor-header {
243303
flex-direction: column;

0 commit comments

Comments
 (0)